Bluetooth with AVAudioSessionPlaybackAndRecord

Hello!


I am working on an app that plays audio and accepts voice commands simultaniously. When I play audio through bluetooth in my car, the Audio Session for the app uses the Bluetooth HFP ports. This causes the output audio quality to become very poor. If I switch to AVAudioSessionPlayback, the output is on the A2DP port, which sounds great. Ideally I would like to be able to play ouput through A2DP, and accept input through HFP, but I assume this is a limitation of bluetooth, or everything would already work this way to improve sound quality. For my app it would be acceptable to accept input from the phone's microphone, and play the audio through bluetooth, but this also seems impossible as described here: http://stackoverflow.com/questions/22146406/ios-input-mic-output-bluetooth-device.


Any advice on improving playback audio quality when connected to bluetooth while using AVAudioSessionPlayback and record would be greatly appreciated. Has anyone encounted this issue before and had a suitable fix?


Thanks!

Accepted Reply

You are correct in that you cannot currently play out via A2DP while accepting input via HFP. There is a comment in the "Note" section of Q&A1799 "AVAudioSession - Microphone Selection" discussing HFP and AVAudioSessionCategoryPlayAndRecord with respect to the Input case. https://developer.apple.com/library/ios/qa/qa1799/_index.html


It is unfortunate that the document formatting is messed up in that the "Note" box doesn't actually surround all the relevant text, but here's the important bit:


"If an application uses the

setPreferredInput:error:
method to select a Bluetooth HFP input, the output will automatically be changed to the Bluetooth HFP output. Moreover, selecting a Bluetooth HFP output using the
MPVolumeView
's route picker will automatically change the input to the Bluetooth HFP input. Therefore both the input and output will always end up on the Bluetooth HFP device even though only the input or output was set individually."


The A2DP route is available to you in AVAudioSessionPlayback but will not be in AVAudioSessionCategoryPlayAndRecord.


Definitely file an enhancement request bug, doesn't matter if it's a duplicate - in fact, the more duplicates the better as this indicates the popularity of the requested feature.

Replies

You could try submitting a enhancement request bug report for this Bluetooth audio capability, but it's very likely a dup, as it's been asked about in the forums here for years.

You are correct in that you cannot currently play out via A2DP while accepting input via HFP. There is a comment in the "Note" section of Q&A1799 "AVAudioSession - Microphone Selection" discussing HFP and AVAudioSessionCategoryPlayAndRecord with respect to the Input case. https://developer.apple.com/library/ios/qa/qa1799/_index.html


It is unfortunate that the document formatting is messed up in that the "Note" box doesn't actually surround all the relevant text, but here's the important bit:


"If an application uses the

setPreferredInput:error:
method to select a Bluetooth HFP input, the output will automatically be changed to the Bluetooth HFP output. Moreover, selecting a Bluetooth HFP output using the
MPVolumeView
's route picker will automatically change the input to the Bluetooth HFP input. Therefore both the input and output will always end up on the Bluetooth HFP device even though only the input or output was set individually."


The A2DP route is available to you in AVAudioSessionPlayback but will not be in AVAudioSessionCategoryPlayAndRecord.


Definitely file an enhancement request bug, doesn't matter if it's a duplicate - in fact, the more duplicates the better as this indicates the popularity of the requested feature.

Curious as to whether any progress has been made on this from Apple. Having a similar challenge where need to play quality audio out and record quality in, all via Bluetooth.
  • you can try

    try recordingSession.setCategory(.playAndRecord, options: [.allowBluetooth, .allowBluetoothA2DP])

    perhaps that helps.

Add a Comment