AudioSession input from bluetooth output to line out or speaker - ios

Once an audio session has been set up the following code allows bluetooth input.
UInt32 allowBluetoothInput = 1;
AudioSessionSetProperty (kAudioSessionProperty_OverrideCategoryEnableBluetoothInput, sizeof (allowBluetoothInput), &allowBluetoothInput);
This code looks like it only allows bluetooth input however this code also routes the audio output to the bluetooth device (in the case of a bluetooth headset). I would like to route the audio output out of the line out or speaker when the input is coming from a bluetooth device. I just want to get audio input from a bluetooth device, I do not want to output audio via bluetooth.
Is this behaviour possible?

as of iOS 5 this behaviour is not possible, quoting apple technical support
Bluetooth devices are not "Jacked In" devices and therefore any other
audio routing must be user picked and cannot be changed in code. To do
this, you can use the functionality of the MPVolumeView which will
have an extra routing widget viewable allowing the user to specify the
routing of the output.
There's a older thread on the Core Audio mailing list regarding this
functionality but behavior hasn't changed:
http://lists.apple.com/archives/coreaudio-api/2009/Oct/msg00030.html
MPVolumeView reference:
http://developer.apple.com/library/ios/#documentation/mediaplayer/reference/MPVolumeView_Class/Reference/Reference.html
However the MPVolumeView does not allow you to route the input and output independently.

Related

Record device audio output with AudioUnit

We need to record the device audio output from cable or bluetooth headset speakers. For example if user listens to some song when Music app runs in background we want to record this song. Is it possible to implement output recording with AudioUnit? We use PalayAndRecord category for shared audioSession with AVAudioSessionCategoryOptionMixWithOthers option.
No, in general you can not listen to the output from another app. There is inter app audio and audio unit technology that enables this, but the connection must be arranged by both apps. It is not possible to just eavesdrop on whatever the user outputs from the device.

How to record voice from a Bluetooth headset for iOS device?

I have an application that needs to record voice from Bluetooth headset. It needs work like Siri or Google Assistant. When I press button in App, it records voice from Bluetooth MIC rather than build in Mic. Is that possible?
My understanding is
1) either the Bluetooth is an Apple certificated External Accessory
2) or the Headset can implement a HFP like protocol to active a HFP link ?
Any hints?
If all you need is recording, it's quite straight if your bluetooth device is paired with iOS. All bluetooth headset with microphone will work well.
When you start to record, I think you have already changed your audio session category to play and record.
Then you can check all your available input route with
-[AVAudioSession availableInputs]
and iterate to find the bluetooth, then set it with
-[AVAudioSession setPreferredInput:error:]
Sometimes it will fail, you need to check the output parameter error to find if there is something wrong.

Record audio in apple watch using bluetooth headset

I know how to record audio using watch speaker. But is there any api available to record using bluetooth headset? So that recording is possible without presenting the audio input controller
Currently there is no such API available to record using Bluetooth headset. If a call is established from watch which has a headset paired does not route voice output to headset rather it uses its default speaker and mic as output and input

iOS: Is it possible to send audio out both headphones and speakers at the same time?

We're looking to send some serial data out from the headphone jack, but would like to still be able to play audio from the speakers. Is it possible to send output to both? If so, is it possible to send different audio to each?
Not as far as I'm aware. You can get programatic notification of when the routing has changed (i.e. when someone connects a headphone cable), but you are unable to specify which device(s) to use for output.

iOS: Route audio-IN thru jack, audio-OUT thru inbuilt speaker

My project involves a magnetic card reader device that plugs into the phono socket (ie only uses microphone)
Can I get my project to output sound through the inbuilt speaker while simultaneously listening for input from the device?
Research suggests this is not possible:
iPhone audio playback: force through internal speaker?
Force iPhone to output through the speaker, while recording from headphone mic
Audio Session Services: kAudioSessionProperty_OverrideAudioRoute with different routes for input & output
The only way round I can see is actually changing the audio session every time I wish to emit a sound.
Is this really the only option? And is it practical to do this? How long would it take for the audio session to reconfigure itself?

Resources