gpt4 book ai didi

ios - 在 ios 上混合音频

转载 作者:行者123 更新时间:2023-12-01 17:46:05 25 4
gpt4 key购买 nike

我正在尝试混合音频源,以便没有音频闪避。我试图解决的用例是在后台进行音频通话,同时播放音乐和/或收听应用程序音频,没有任何音频闪避。音频闪避是指音频被降低并略微失真以帮助收听另一个 Audio Session 。我可以不加掩饰的音频和音频混合(或 iOS)吗?

我已经尝试了以下代码。我也尝试将它包装在 DispatchQueue.main.async 闭包中,但仍然没有运气。


// I have also tried this code with this block uncommented
// do {
// try audioSession.setActive(false, options: .notifyOthersOnDeactivation)
//
// } catch let activationError {
// print(activationError)
// print(activationError.localizedDescription)
// }


let audioSession = AVAudioSession.sharedInstance()
do {
try audioSession.setCategory(
AVAudioSession.Category.playAndRecord,
mode: AVAudioSession.Mode.voiceChat,
options: [.allowBluetoothA2DP, .allowBluetooth, .mixWithOthers, .allowAirPlay]
)
} catch let setCategoryError {
print(setCategoryError)
print(setCategoryError.localizedDescription)
}

do {
try audioSession.setActive(true, options: .notifyOthersOnDeactivation)

} catch let activationError {
print(activationError)
print(activationError.localizedDescription)
}

最佳答案

答案似乎是 AVAudioSession.Mode 在后台自动设置了一些选项。 Apple 似乎做出了设计决定,即 .voiceChat 模式应该始终避开其他模式以获得最佳体验。在 .videoChat 模式中也是如此,这两种模式都是用于 Agora 调用的明显模式。使用这些模式似乎会自动设置 .duckOthers 标志。

我可以通过将模式设置为 .videoRecording 来解决这个问题,专为录制音频和视频的应用程序而设计,因此不会自动设置 .duckOthers。因为这实际上不是您正在做的事情,所以这绝对是一种解决方法,并且可能会产生其他副作用。

鉴于您对 AVAudioSession 所做的事情,您可能还希望阻止 Agora 从您的下方更改它。您可以调用agoraKit.setAudioSessionOperationRestriction(.all)以防止 Agora 在未经您许可的情况下更改全局 AVAudioSession,这可能是完成这项工作所必需的。

关于ios - 在 ios 上混合音频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62708625/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com