【问题标题】:AirPods not working as an input source for Voice Recorder AppAirPods 不能作为 Voice Recorder App 的输入源
【发布时间】:2017-03-17 16:26:36
【问题描述】:

出于某种原因,我的录音机应用不会使用 AirPods 作为输入源。开始录音后,输入源从 AirPods 变为 iPhone 麦克风。不知道如何解决它。

【问题讨论】:

  • 您设置了什么音频会话类别和模式?参考:developer.apple.com/reference/audiotoolbox/…
  • 嘿,Eddie,刚刚签到看看你能不能解决这个问题。我们最近遇到了同样的问题,但也无法确定缺少什么。

标签: ios swift


【解决方案1】:

在连接 AirPods 时,有两种方法可以录制和播放音频。对于这两种情况,我们将使用AVAudioSessionCategoryPlayAndRecord 类别。诀窍是管理AVAudioSessions 选项集。

  1. 添加.allowBluetoothA2DP 选项。这将允许您通过 AirPods 收听音频并使用内置麦克风进行录音。
  2. 添加.allowBluetooth 选项。使用此选项,您可以在播放期间使用 AirPods 录制音频。但在这种情况下,音频质量会降低。

【讨论】:

    【解决方案2】:

    埃迪, 如果您仍然遇到问题,请查看我发布的类似帖子,我们最终能够解决我们遇到的问题。

    AVAudioRecorder/AVAudioSession with Apple Airpods

    【讨论】:

      【解决方案3】:

      首先我捕获可用的输出源。

      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)
      

      【讨论】:

        【解决方案4】:

        对我有用

        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)
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2018-05-27
          • 1970-01-01
          • 2021-11-02
          • 2022-11-21
          • 2015-12-20
          • 2019-12-05
          • 2023-01-18
          • 2019-04-05
          相关资源
          最近更新 更多