为什么AVAudioEngine无法从我的蓝牙耳机输入中转换格式? 我的问题:注意:

问题描述

我一直在使用AVAudioEngine从麦克风中获取音频,并通过WebRTC连接将其发送出去。当我使用iPhone设备的麦克风时,这似乎可以正常工作。但是,如果我在连接蓝牙耳机的情况下运行该应用,则引擎在尝试启动时会报告此错误:

[avae]  AVAudioEngine.mm:160   Engine@0x2833e1790: could not initialize,error = -10868
[avae]  AVAEInternal.h:109   [AVAudioEngineGraph.mm:1397:Initialize: (err = AUGraphParser::InitializeActiveNodesInInputChain(ThisGraph,*GetInputNode())): error -10868
Error starting audio engine: The operation couldn’t be completed. (com.apple.coreaudio.avfaudio error -10868.)

我看到错误代码-10878是:

@constant       kAudioUnitErr_FormatNotSupported
Returned if an input or output format is not supported
...
kAudioUnitErr_FormatNotSupported        = -10868

,但这似乎并不完全正确。我知道支持输出格式,因为未连接耳机时相同的格式可以正常工作。而且我非常确定支持输入格式,因为我可以简单地挂接Headphones InputNode -> Mixer -> Headphones OutputNode并正确听到麦克风的音频。

所以我只能假设这表示不支持格式转换

我的问题:

  1. 这是一个错误吗?
  2. 有什么办法可以解决这个问题吗?

注意:

  • 我的完整音频图看起来像这样,其中所有“混音器”都只是AVAudioMixerNode
// InputNode (Mic)  ->  Mic Mixer -\
//                                   >->    WebRTC Mixer -> Tap -> WebRTC Framework
// AudioPlayer 1 -> Player Mixer  -/
//
// AudioPlayer 2 -> Player Mixer -----> LocalOutputMixer -> OutputNode (Device Speakers/Headphones)

但是即使我简化为这个问题,问题仍然会发生:

InputNode (Mic)  ->  Mixer -> Tap -> WebRTC Framework

具体来说,当单个混音器节点以如下输入格式和输出格式连接时会发生:

  • 输入格式为:
(lldb) po audioEngine.inputNode.inputFormat(forBus: 0).streamDescription.pointee
▿ AudioStreamBasicDescription
  - mSampleRate : 16000.0
  - mFormatID : 1819304813
  - mFormatFlags : 41
  - mBytesPerPacket : 4
  - mFramesPerPacket : 1
  - mBytesPerFrame : 4
  - mChannelsPerFrame : 1
  - mBitsPerChannel : 32
  - mReserved : 0
  • WebRTC期望的输出格式为:
▿ AudioStreamBasicDescription
          - mSampleRate : 48000.0
          - mFormatID : 1819304813
          - mFormatFlags : 12
          - mBytesPerPacket : 2
          - mFramesPerPacket : 1
          - mBytesPerFrame : 2
          - mChannelsPerFrame : 1
          - mBitsPerChannel : 16
          - mReserved : 0
  • 我的耳机是Jaybird Freedom 2。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)