【问题标题】:error while connecting input node to AVAudioSinkNode将输入节点连接到 AVAudioSinkNode 时出错
【发布时间】:2020-10-25 21:10:50
【问题描述】:

连接节点时出错

let sourceNode = AVAudioSinkNode { (test1, frameCount, audioBufferList) -> OSStatus in
    print("callback", self.testInteger)
    return noErr
}
audioEngine.attach(sourceNode)
audioEngine.connect(audioEngine.inputNode, to: sourceNode, format: nil)

[aurioc] AURemoteIO.cpp: 1086: Initialize: failed: -10851 (启用 1, outf inf )

然后try audioEngine.start () 出现错误

[avae] AVAEInternal.h: 88 所需条件为假:[AVAudioEngineGraph.mm:1415:Initialize: (IsFormatSampleRateAndChannelCountValid (inputHWFormat))] [avae] AVAudioEngine.mm:160 Engine @ 0x2836a8940: 无法初始化,错误 = -10875 [avae] AVAEInternal.h: 88 所需条件为假:[AVAudioEngineGraph.mm:1415:Initialize: (IsFormatSampleRateAndChannelCountValid (inputHWFormat))]

我也试过

audioEngine.connect (audioEngine.inputNode, to: sourceNode, format: audioEngine.inputNode.inputFormat (forBus: 0))

audioEngine.connect (audioEngine.inputNode, to: sourceNode, format: audioEngine.inputNode.outputFormat (forBus: 0))

在这两种情况下,应用程序崩溃并出现错误 “由于未捕获的异常'com.apple.coreaudio.avfaudio'而终止应用程序,原因:'所需条件为假:IsFormatSampleRateAndChannelCountValid(格式)”

【问题讨论】:

  • format: nil 错误。
  • @matt 是的,我意识到这是错误的,但我仍然不明白我应该改用什么,我尝试了其他格式(我在我的问题中写过)但它们也不起作用.你能告诉我应该使用哪种格式吗?

标签: swift avfoundation core-audio avaudioengine


【解决方案1】:

我发现有必要将音频会话的类别 playAndRecord 放置

try audioSession.setCategory (.playAndRecord, mode: .spokenAudio, options: .defaultToSpeaker)

在这种情况下,此选项有效

audioEngine.connect (audioEngine.inputNode, to: sourceNode, format: audioEngine.inputNode.inputFormat (forBus: 0))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-10
    • 2017-06-24
    • 2019-05-26
    • 1970-01-01
    • 2018-12-25
    相关资源
    最近更新 更多