Record on built in mic and simultaneously playback processed audio on AirPods

Basically for this iPhone app I want to be able to record from either the built in microphone or from a connected USB audio device while simultaneously playing back processed audio on connected AirPods. It's a pretty simple AVAudioEngine setup that includes a couple of effects units. The category is set to .playAndRecord with the .allowBluetooth and .allowBluetoothA2DP options added. With no attempts to set the preferred input and AirPods connected, the AirPods mic will be used and output also goes to the AirPods. If I call setPreferredInput to either built in mic or a USB audio device I will get input as desired but then output will always go to the speaker. I don't really see a good explanation for this and overrideOutputAudioPort does not really seem to have suitable options.

Testing this on iPhone 14 Pro

Replies

Looking at the route change notification that occurs the reason indicated is override which has the following interesting comments noted in it's definition:

/// The route has been overridden (e.g. category is AVAudioSessionCategoryPlayAndRecord and
        /// the output has been changed from the receiver, which is the default, to the speaker).
        case override = 4

Which basically describes my situation. So it seems to be on purpose - but why? I can see that others have struggled with the same issue in iOS 16 and have found that the only solution is writing Core Audio code in C, something I definitely have no desire to do - been there done that