Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select Back Microphone on iPhone 5

Is there a way for RemoteIO unit to pick up back microphone on iPhone 5 ? I can configure AVAudioSession to choose between front microphone or bottom microphone but I can't find a way to select the back Microphone.

The AVFoundation framework for sure uses the back microphone for video recording when using the back camera, but I want a way to choose the same using CoreAudio. Is that possible ?

like image 638
Deepak Sharma Avatar asked Jan 21 '13 20:01

Deepak Sharma


People also ask

How do I get the microphone back on my iPhone?

Go to Settings > Privacy > Microphone. Make sure that the app is enabled.


2 Answers

Setting kAudioSessionProperty_Mode to kAudioSessionMode_VideoRecordingwith AudioSessionSetProperty uses the microphone nearest to the camera, which should be the back microphone. That's if you use the Audio Session Services. AVAudioSessionModeVideoRecordingif you're using AVFoundation to record. The doc says "Using this mode may result in the system providing appropriate audio signal processing." which I interpet as "we may also use the other mics for noise cancelling".

like image 176
HBu Avatar answered Nov 02 '22 08:11

HBu


Use AVAudioSession to get available inputs. On my iPhone 5 it looks like this.

NSLog(@"%@", [AVAudioSession sharedInstance].availableInputs);

  "<AVAudioSessionPortDescription: 0x14554400, type = MicrophoneBuiltIn; name = iPhone Microphone; UID = Built-In Microphone; selectedDataSource = Back>"

Then use one of these inputs to get availableDataSources, like this.

NSLog(@"%@", [AVAudioSession sharedInstance].availableInputs[0].dataSources);

  "<AVAudioSessionDataSourceDescription: 0x145afb00, ID = 1835216945; name = Bottom>",
  "<AVAudioSessionDataSourceDescription: 0x145b1870, ID = 1835216946; name = Front>",
  "<AVAudioSessionDataSourceDescription: 0x145b3650, ID = 1835216947; name = Back>"

Now you can set your preferred data source.

AVAudioSessionPortDescription *port = [AVAudioSession sharedInstance].availableInputs[0];
for (AVAudioSessionDataSourceDescription *source in port.dataSources) {
    if ([source.dataSourceName isEqualToString:@"Back"]) {
        [port setPreferredDataSource:source error:nil];
    }
}
like image 30
Tony Weber Avatar answered Nov 02 '22 07:11

Tony Weber