1

An app that I built has always output its audio through the bottom speaker (speakerphone), but it now outputs to the front (ear) speaker. I have not changed the app, so I assume the cause must be iOS 14.2, which I recently installed.

The app uses AVAudioSession, setting AVAudioSession.Category to .playAndRecord because it performs both audio recording and speech synthesis.

Any idea what 14.2 may have changed to cause this… and how I can specify that the output go to the bottom speaker?

Anton
  • 2,512
  • 2
  • 20
  • 36

1 Answers1

1

It turns out that it was simply a matter of adding .defaultToSpeaker during setup:

try AVAudioSession.sharedInstance().setCategory(.playAndRecord, options: .defaultToSpeaker)

I'm not sure why the option was only necessary beginning with iOS 14.2, but it solves the problem.

Anton
  • 2,512
  • 2
  • 20
  • 36
  • Any more recent info? We don't want to default to the speaker, but when we *are* using the speaker we'd like it to also use the bottom speaker and not just the earpiece! – Meekohi Jan 31 '22 at 19:30
  • @Meekohi using the speaker means never using the earpiece. But this won't affect things if you're using a bluetooth device, etc. So I think this is what you want. – Anton Jan 31 '22 at 23:33
  • I haven't figured out any way to get the behavior you're describing -- if I use `defaultToSpeaker` then the output *always* goes to the speaker, even when Bluetooth headsets are connected. – Meekohi Feb 03 '22 at 16:51
  • @Meekohi to be honest I've only tested it with plug-in headphones rather than bluetooth - but that does override the speaker fine. In the Apple docs it says: "The use case is to route audio to the speaker instead of the receiver in cases where the audio would normally go to the receiver." — which sounds to me like exactly what you are seeking. I'm sorry it's not working for you. https://developer.apple.com/documentation/avfaudio/avaudiosession/categoryoptions/1616462-defaulttospeaker – Anton Feb 03 '22 at 19:06