AirPods not working as an input source for Voice Recorder App

前端 未结 4 1149
离开以前
离开以前 2020-12-18 13:26

For some reason, my voice recorder app won\'t use AirPods as an input source. Upon beginning a recording, the input source changes from the AirPods to the iPhone microphone.

相关标签:
4条回答
  • 2020-12-18 13:29

    It is worked for me

    try? AVAudioSession.sharedInstance().setCategory(.playAndRecord, options: [.allowBluetooth, .allowBluetoothA2DP]
    
    if let headphones = AVAudioSession.sharedInstance().availableInputs?.first(where: { $0.portType == .bluetoothHFP || $0.portType == .bluetoothA2DP || $0.portType == .headphones }) {
        try? AVAudioSession.sharedInstance().setPreferredInput(headphones)
    }
    
    try? AVAudioSession.sharedInstance().setActive(true)
    
    0 讨论(0)
  • 2020-12-18 13:36

    Firstly i catch available output source.

    let currentOutputSource = AVAudioSession.sharedInstance().outputDataSource
    try? AVAudioSession.sharedInstance().setCategory(.playAndRecord, options: [.allowBluetooth, .allowBluetoothA2DP])
    if let currentOutputSource = currentOutputSource {
        // Then i set known output source to input source.
        try AVAudioSession.sharedInstance().setInputDataSource(currentOutputSource)
    }
    try? AVAudioSession.sharedInstance().setActive(true)
    
    0 讨论(0)
  • 2020-12-18 13:37

    There are two ways to record and play audio while AirPods are connected. For both cases we will use AVAudioSessionCategoryPlayAndRecord category. The trick is to manage AVAudioSessions option set.

    1. Add .allowBluetoothA2DP option. This will allow you to listen audio via AirPods and record with internal mic.
    2. Add .allowBluetooth option. With this option you can record audio with AirPods during playback. But in this case audio quality will be reduced.
    0 讨论(0)
  • 2020-12-18 13:52

    Eddie, If you're still having the issue, please see a similar post I made that we were able to finally resolve the issues we were having.

    AVAudioRecorder/AVAudioSession with Apple Airpods

    0 讨论(0)
提交回复
热议问题