iOS: How to choose which microphone (inbuilt/external) to use? - ios

Let us say I have an audio iPhone app which takes input from the microphone.
Now, although I haven't tried this myself, I believe the user could use an external microphone that plugs into the phonojack socket.
This means my audio unit could be receiving its input from the internal or the external microphone.
My guess is that iOS will automatically route from an external microphone if it is connected.
But what if I don't want that?
Is there a way to specify which microphone should be used?
I have looked in the audio session guide, I can find some setting regarding a Bluetooth headset. But that is as close as I can find. It appears that it is not possible. But I find that difficult to believe.
PS Also I am curious how it detects an external microphone... if I plug my headphones in, it should continue routing from the internal microphone. my headphones are just plain stereo headphones. but if I used my mobile phone's headphones ( on extra band on the Jack... they have a microphone built onto the cable where the individual earpiece strands meet ) I would expect it to pick up this source instead.

You have to use the AUHAL unit to set a specific input device as default input and then connect it with the AudioQueue.
Apple has a detailled Technical Note for that: Device input using the HAL Output Audio Unit

Related

Can I use AVAudioRecorder with an external mic?

Sorry if this question is obvious or duplicated. My 30 minutes of research led me nowhere.
We have an iPhone app that live streams video from the device to our remote Wowza servers.
We're looking to integrate the Swivl (motion tracking tripod) into our product, and it uses a wireless microphone that feeds into the 30-pin port of our iPhone. Swivl's SDK doesn't include anything about capturing audio from their hardware so I assume that it would be handled by the iPhone itself.
If I use the AVAudioRecorer, will it automatically route the audio input from the 30-pin port instead of the default microphone, or do I have to explicitly define the audio source?
Any clues help.
After a few tests, it seems that iOS automatically routes incoming audio signals.
There is no need to explicitly specify the source of the audio.
Straight from AVAudioRecorder documentation:
In iOS, the audio being recorded comes from the device connected by the user—built-in microphone or headset microphone, for example. In OS X, the audio comes from the system’s default audio input device as set by a user in System Preferences.

How to switch off audio output ios?

Is it possible to switch off audio output on device?
I need route the sound to phone's speaker when headphones are connected.
I need to connect some device via audio output(like connect headphones) but if i connected it the voice on ios device is blocked. I want turn off audio output and turn on when i need use this device.
This goes against Apple's Human Interface Guidelines. If you read the section on Technology usage you find a section labelled Sound. It describes the expected behaviour when using headphones:
http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/MobileHIG/TechnologyUsage/TechnologyUsage.html#//apple_ref/doc/uid/TP40006556-CH18-SW3
I don't think so you can do this. Because apple is very strict and stick with their functionality.

iPhone headphone audio jack re-routing

We created an external iOS notification light that uses the device’s audio for power.
When you get a phone call on iPhone and the light is plugged in, you still get the ringtone but when you pick up, the audio is rerouted to the headphones (the iPhone thinks our light/device is a headphones set) and the user has to extract myLED for at least 2mm to get the audio from the front receiver of the phone.
We have been exploring alternative solutions to this challange - recently we made a prototype with a particular jack shape so that it could be rotated by the user when getting a call to "reroute" the audio to the iPhone speaker/mic.
Although it may sound a clever option, this hardware solution is far from being neat - this leads to having positions where the myLED does not work/ it is not reliable, plus other complications.
I know of the existence of kAudioSessionOverrideAudioRoute_Speaker however I suspect that this will only direct the app audio to the rear speaker (the “loud” one) and not to the front receiver (because the “receiver” for the iphone is the headphones set if they are detected).
What would you suggest?
Super appreciated!
I think you're in a tough spot:
It's highly unlikely Apple will ever release the option to override audio routing for phone calls. As a key functionality of the phone, they tend to keep the call aspect under lock and key.
The headphone jack (probably - this is how most of them do it) uses the impedance between ground and one or both speakers or the remote control to determine if the plug is in. Other than breaking the circuit, there is no good way to simulate this.
The only options I think you have are these:
Require the user to remove the device when a call comes in.
Provide a microcontroller on the jack to drive a transistor; this transistor can electronically break the circuit to provide the same sort of impedance signature as an unplugged jack.
How, when, and if you can provide the information to the jack that a phone call is in progress is beyond my knowledge: is there an API for "incoming but not yet answered call" you can hook to? Will you have to do a watchdog thing to ensure communication with your app? Would it be possible for you to use the dock connector instead? I think these are really your options. Not a complete answer, but those are my thoughts.

Intercom with Bluetooth headset

I've been researching the ability to create a bi-directional audio link between iOS and a bluetooth audio headset.
What I need to be able to do is:
When the user speaks into the microphone on the iOS device, that audio should be redirected to the audio out of the headset, the piece.
When the microphone of the headset picks up audio, that should come out the speaker of the iOS device.
In my searching I've found that you can:
Enable bluetooth audio input and output:
how to route iPhone audio to the bluetooth headset
Redirect input to speaker:
Mic input to the speaker output on an iOS device?
After reading this:
AudioSession input from bluetooth output to line out or speaker
I'm thinking what I want to do cannot be done.
So before I get to testing, does anyone know if what I'm trying to do is even possible. From the last link it appears you can only have one input and output pair at a time. What I'm trying to do would require two pairs of input and output. In from BT, out to iOS speaker. In from iOS Mic, out to BT.
Thank you!
The current public iOS Audio Session APIs appear to only support a single audio route pair (input+output).

Audio Unit: Use sound output as input source

I want to process the stereo output from iOS devices, no matter what application causes them and visualize it in real-time.
Is it possible to use the generic output device (or anything else) to get at the audio data which are currently being played? Maybe as an input to a remoteIO unit?
In other words: I want to do what aurioTouch2 does (FFT only) but instead of using the microphone as input source, I want to process everything which is coming out of the speakers at a given time.
Kind regards
If your own app is playing using the RemoteIO Audio Unit, you can capture that content. You can not capture audio your app is playing using many of the other audio APIs. The iOS security sandbox will prevent your app from capturing audio that any other app is playing (unless that app explicitly exports audio via the Inter-App Audio API or equivalent).

Resources