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.

  • Audio Not Recording in AVCaptureSession
  • Determining the relative position of 2 mobile devices using ultrasound
  • How to mute/unmute audio when playing video using MPMoviePlayerController?
  • How to get the duration of an audio file in iOS?
  • Code sample for capturing audio from a Mac in Cocoa and saving to file?
  • objective c audio meter
  • 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?

    Solutions Collect From Internet About “Recording from Built-In Mic when Playing through Bluetooth in iOS”

    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.