4
votes

I am trying to implement a feature in Objective-C where the use case requires the user to speak into a Hands-Free bluetooth headset and have their voice mix with an audio file and play both over the headphone jack.

I have the program working and will allow mixing of microphone and audio over the HFB, or using a wired microphone. But the audio always plays the same place as the microphone source. I cannot find a way to override only audio output to the headphone jack.

I used the following code, which I found in the documentation to override output to the speaker, but I cannot find one to force audio to the headphone jack:

[[AVAudioSession sharedInstance] overrideOutputAudioPort:AVAudioSessionPortOverrideSpeaker error:nil];

Another problem with the above line of code is that it overrides input and output to the built in speaker and built in microphone.

Back to my use case - I need to use hands free bluetooth to voice over audio going out of the headphone jack. Any ideas how this can be implemented?

1

1 Answers

3
votes

I have a very similar use case but after searching the Apple Documentation and speaking with Apple directly, it's not currently possible to set the input and output data sources/ports independently.

Per Apple's documentation:

https://developer.apple.com/library/ios/qa/qa1799/_index.html

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.

Submit a bug report to Apple. They may change it if there are enough complaints.