AVCaptureSession with BluetoothHFP device

2019-08-15 06:07发布

问题:

I need to stream the voice data to server, so I can't use AVAudioRecorder. Here is my approach.

set it Allow Bluetooth and activate it

NSError* e;
AVAudioSession* audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryRecord
                                     withOptions:AVAudioSessionCategoryOptionAllowBluetooth
                                           error:nil];
[audioSession setActive:YES withOptions:0 error:&e];

I did setup the notification for AVAudioSessionRouteChangeNotification so I see the input source changed to BluetoothHFP

but seems there is no way to configure a BluetoothHFP input to AVCaptureDeviceInput.

    self.captureSession = [[AVCaptureSession alloc] init];
        self.captureSession.sessionPreset = AVCaptureSessionPresetLow;

    AVCaptureDevice* captureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];

    AVCaptureDeviceInput* audioInput = [AVCaptureDeviceInput deviceInputWithDevice:captureDevice error:&error];

    if(audioInput && [self.captureSession canAddInput:audioInput]){
        [self.captureSession addInput:audioInput];
    }

after doing so, the input source changed to iPhone MicroPhone.

is there anyway I can get the BluetoothHFP input as AVCaptureDeviceInput??