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
671 views
in Technique[技术] by (71.8m points)

iphone - Recording from Built-In Mic when Playing through Bluetooth in iOS

Is it possible to receive audio input from iPhone's built-in microphone, and play that audio through a Bluetooth headset, at the same time?

My goal is to always use the built-in microphone as the input device, even if the output device is a headset, because the built-in microphone is more convenient in my use cases.

I know how to achieve my goal when the output device is a wired headset, like the one that comes bundled with an iPhone. I simply plug the wired headset in, and call the following method:

- (void)selectBuiltInMicrophone
{
    AVAudioSession *session = [AVAudioSession sharedInstance];
    for (AVAudioSessionPortDescription *port in session.availableInputs)
        if ([port.portType isEqualToString:AVAudioSessionPortBuiltInMic]) {
            NSError *error;
            [session setPreferredInput:port error:&error];
            break;
        }
}

By calling the above method, the input device will be switched from the wired headset's microphone to iPhone's built-in microphone, while the output device remains unaffected, so the iPhone will record from the built-in microphone and play through the wired headset. This is what I expect.

The problem is, this method does not work when the headset is a Bluetooth one. If I connect a Bluetooth headset to the iPhone, then call the above method, the built-in microphone will becomes the input device, which is great, but the output device will also be changed to iPhone's receiver, which is bad.

It seems that the input and the output of a Bluetooth headset are locked together: you either use both of them, or you use none of them. Is my goal really impossible? Or there exists a way to overcome the apparent limitation?

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

It is not possible to receive audio input from iPhone's built-in microphone, and play that audio through a Bluetooth headset, at the same time

  1. There is a prevention that you can use like a walkie-talkie .
  2. you have to create Two sessions . Means while recording audio you have to enable audio session with recordandplay.
  3. while Playing you have to set the option to audiosession (allowingBluetooth) .
  4. While Recording You have to set recordandplay.

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

...