I'm developing an iPhone application and want to playback and record sound from the bottom speaker and microphone without any embedded audio processing. If I use the following code, the sound comes from the top speaker. If I also add "try playbackSession.setCategory(AVAudioSession.Category.multiRoute)" then the sound comes from both the top and bottom speaker. If I use any other setMode than measurement, then there is an embedded audio processing that I want to avoid.
playbackSession = AVAudioSession.sharedInstance()
do { try playbackSession.overrideOutputAudioPort(AVAudioSession.PortOverride.speaker) try playbackSession.setMode(AVAudioSession.Mode.measurement)) } catch {print("Playing over the device's speakers failed") }
I got this answer from apple support regarding this issue. This solved my problem. I hadn't added the option mixWithOthers.
With the following code (in a basic iOS app from the Xcode template, using Xcode 13.2 with iOS 15.2):
override func viewDidLoad() {
super.viewDidLoad()
let session = AVAudioSession.sharedInstance()
try! session.setCategory(.playAndRecord, mode: .measurement, options: [.mixWithOthers, .defaultToSpeaker])
try! session.setActive(true)
print(session.currentRoute)
}
I get the following output:
<AVAudioSessionRouteDescription: 0x28348c9a0,
inputs = (
"<AVAudioSessionPortDescription: 0x28348c960, type = MicrophoneBuiltIn; name = iPhone Microphone; UID = Built-In Microphone; selectedDataSource = Bottom>"
);
outputs = (
"<AVAudioSessionPortDescription: 0x28348c8e0, type = Speaker; name = Speaker; UID = Speaker; selectedDataSource = (null)>"
)>
That seems to be what you want: both input and output at the bottom of the device. Is this the configuration you’re looking for?