AVAudioSession 'defaultToSpeaker' kills mic input on iPhone

In the existing version of my app, GuitarParrot, it was necessary to use '.defaultToSpeaker' to get the sounds to play from the Speaker, not the Receiver. Now this same setting is disabling the microphone.

This problem doesn't occur on iPads, but I have confirmed the issue on an iPhone7S and an iPhoneXR.

I am in the process of updating my app to be compliant with iOS 15 and Xcode 13. The use of '.defaultToSpeaker' is killing the mic input. If I remove this setting, then the mic input works as desired, but sound is sent to the Receiver speaker. I have hunted down dozens of audio code, yet I am not finding anyone doing this differently than myself. Here is the statement I'm using to initialize the session. What am I doing wrong?

let audioSession: AVAudioSession = AVAudioSession.sharedInstance() try audioSession.setCategory(AVAudioSession.Category.playAndRecord,                                  mode: AVAudioSession.Mode.gameChat,                                  options: [.defaultToSpeaker, .mixWithOthers]) try audioSession.setActive(true)

I have tried many variations (different modes, adding bluetooth). The only method that allows the mic to work is to remove '.defaultToSpeaker' from the options.

Any help is greatly appreciated.

Extra detail: My app is written using Flutter. All of the AVAudioSession initialization is done using a Swift plugin. I also downloaded the newly-released demo from AudioKit and it also defaults sound to the receiver speaker when the demo is run on an iPhone.

Add a Comment

Replies

Retested the AudioKit "Cookbook" app with Xcode Version 14.0.1 (14A400) and iOS 15.7 and 'defaultToSpeaker' is now working as expected. Retested on my app and the mic is now working when 'defaultToSpeaker' is an option.

Also, the mode on the initial post as gameChat, but I had changed it back to default. This didn't affect the issue when I posted, but mode is default now and things are working.

To that end, it appears that this AVAudioSession init string is correct and some glitch worked itself out over the last month:

let audioSession: AVAudioSession = AVAudioSession.sharedInstance() try audioSession.setCategory(AVAudioSession.Category.playAndRecord, mode: AVAudioSession.Mode.default, options: [.defaultToSpeaker, .mixWithOthers]) try audioSession.setActive(true)

Nope, I was mistaken. My app still kills the mic if '.defaultToSpeaker' is used. Likely caused by mixing plugins, using one for mic capture and the other for midi playback. AudioKit Cookbook works as expected, so it doesn't appear to be an 'Apple' issue, it's an ID10T group effort problem.