Recording from Built-In Mic when Playing through B

2019-01-26 17:33发布

问题:

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?

回答1:

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.