【发布时间】:2015-12-17 23:29:14
【问题描述】:
我正在开发一个 VoIP 应用程序,它使用 MPVolumeView 来允许用户调整系统音量。在 iOS 9.1 发布之前,这一切都运行良好。然后我发现如果我将AVAudioSession 模式设置为AVAudioSessionModeVoiceChat,MPVolumeView 滑块就坏了。 (即滑块不再调节系统音量。)如果我将模式更改为AvAudioSessionModeDefault,MPVolumeView 将按预期工作,但我的麦克风会记录来自 iPad 扬声器的音频。 (换句话说,语音处理已关闭——我需要 VoIP 呼叫。)在 iOS 9.1 之前,我可以将 AudioSession 模式设置为AVAudioSessionModeDefault,然后在 AudioComponentDescription 中将 componentSubType 设置为kAudioUnitSubType_VoiceProcessingIO,一切正常美好的。不幸的是,情况似乎不再如此。有谁知道如何在 iOS 9.1 之后保持语音处理并让 MPVolumeView 工作?
这是我设置 AVAudioSession 的代码:
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
// Make sure the session on this thread matches.
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionMixWithOthers | AVAudioSessionCategoryOptionAllowBluetooth error:nil];
// Here is the main connundrum: I want to set AVAudioSessionModeDefault so that the MPVolumeView will work,
// but when I do that the mic picks up the audio from the speaker and plays it back creating an unwanted feeback loop.
// If I set the mode to AVAudioSessionModeVoiceChat the voice processing (primarily the AEC) fixes the feeback loop,
// but then the MPVolumeView no longers works. (It no longer adjusts the system volume.
//Question: How can I have BOTH the voice processing AND the MPVolumeView adjust the system volume?
if(!appDelegate.viewController.voiceChatMode)
[audioSession setMode:AVAudioSessionModeDefault error:nil];
else
[audioSession setMode:AVAudioSessionModeVoiceChat error:nil];
[audioSession setPreferredIOBufferDuration:0.005 error:nil];
[audioSession setActive:YES error:nil];
【问题讨论】:
-
您问题中的代码在 iOS 9.2 上运行良好(
MPVolumeView在设置AVAudioSessionModeVoiceChat模式时启用)。是否需要主动记录才能重现问题? -
可能。在我的示例项目中,我让它录制音频并将其播放回扬声器,但当我让 VoIP 应用程序录制语音音频并播放来自另一个用户的音频时,这也是一个问题。你有它工作的例子吗?我问是因为我的简单测试失败了。
-
我所拥有的唯一示例完全符合您在上述代码 sn-p 中的操作,抱歉。
-
这仍然是使用 voicePrompt 模式的 iOS 13 上的问题。
标签: ios objective-c