record input coming from bluetooth headset in iPhone

后端 未结 3 2143
长情又很酷
长情又很酷 2020-12-09 13:09

I have a project in which I have to record the voice coming from bluetooth headset and play with default iPhone speaker. I have searched a lot and got this code.

<         


        
3条回答
  •  自闭症患者
    2020-12-09 14:00

    Try out this amazing piece of code. Will work for sure

    AVAudioSession *audioSession = [AVAudioSession sharedInstance];
    NSError *err = nil;
    [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionAllowBluetooth  error:NULL];
    [audioSession setActive:YES error:NULL];
    
    NSString *preferredPortType = AVAudioSessionPortBluetoothHFP;
    for (AVAudioSessionPortDescription *desc in audioSession.availableInputs)
    {
        if ([desc.portType isEqualToString: preferredPortType])
        {
            [audioSession setPreferredInput:desc error:nil];
        }
    }
    

提交回复
热议问题