5

We are developing an app that needs to change the audio route in iOS. We need to get some information from the mic input and then change to the internal mic of the device to record ambient sound.

We have seen 2 topics from these pages: Forcing iPhone Microphone as Audio Input and Use built-in mic if Headset is plugged in but i guess there isn't any final word according to this situation.

Now, the code works but we can select the route of the audio input.

We haven't found anything in the documentation provided by Apple (Remote IO).

Is there anything new about this?

Thanks!

Community
  • 1
  • 1
the_moon
  • 553
  • 1
  • 7
  • 21

1 Answers1

2

Warning: This answer applies to iOS6 only. It is not correct for iOS7 or later. See comments for details.

This is possible, but only with a side effect. Changing the input device also changes the output device. You will not be able to record through the internal mic and at the same time listend to your recording in realtime through the headset's headphones. That means that if you do not want to listen simultaneously to your recording through the headphones, there is a solution for you:

When having connected a headset (= combined headphones and mic), you can choose between two alternatives:

  • internal mic for input and speaker for output
  • headset's mic for input and headset's headphones for output

(You can not use a mixture of these.)

You choose one of the alternatives by setting the property kAudioSessionProperty_OverrideAudioRoute through the function AudioSessionSetProperty of the Audio Session Services API. The documentation of the property says:

If a headset is plugged in at the time you set this property’s value to kAudioSessionOverrideAudioRoute_Speaker, the system changes the audio routing for input as well as for output: input comes from the built-in microphone; output goes to the built-in speaker.

Daniel S.
  • 6,458
  • 4
  • 35
  • 78
  • 1
    Note that the iPhone is able to distinguish between a headset (combined microphone and headphones) and sole headphones. It behaves differently for these two device types regarding the route changes, because it obviously can not change the input route when connecting only headphones without integrated microphone. I did not test the exact behavior in such a case. – Daniel S. Jul 22 '13 at 21:11
  • 5
    It is deprecated on iOS 7, use AVAudioSession - setPreferredInput: – Labokas Mar 22 '14 at 11:11
  • 2
    Iwaz's comment is very important: Now, in iOS7, it is possible for an App to independently select input routes and output routes. E.g. you can use the internal microphone to record sound and play this sound simultaneously through a connected headset's earphones, while the headset's microphone remains unused. This was not possible in iOS6. The extended API is in the AVAudioSession class. – Daniel S. Jul 19 '14 at 10:38
  • @DanielS. can you provide an example how you can play and record from different routes? Using which api? – zo_chu Nov 20 '17 at 08:08
  • @zo_chu The API has changed since I posted this answer. I haven't worked with the new API yet, so I can't give you an example, simply because I'm not an up to date expert on this anymore. However, because what you asked is important, I think it's worth the time that you open up another question on stackoverflow to get the right amount of attention for this topic. Moreover, the successful expert who sheds some light on it then has the chance to earn the points for his work. – Daniel S. Nov 21 '17 at 15:44