Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
625 views
in Technique[技术] by (71.8m points)

audio - Choose between built in mic and headset in iOS

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...