输入节点连接到AVAudioSinkNode时出错

问题描述

连接节点时出现错误

let sourceNode = AVAu@R_502_6230@SinkNode { (test1,frameCount,audiobufferlist) -> Osstatus in
    print("callback",self.testInteger)
    return noErr
}
au@R_502[email protected](sourceNode)
au@R_502[email protected](au@R_502[email protected],to: sourceNode,format: nil)

[aurioc] AURemoteIO.cpp:1086:初始化:失败:-10851(启用1,outf inf )

此后,当try au@R_502[email protected] ()

时出现错误

[avae] AVAEInternal.h:88必需条件为假:[AVAu@R_502[email protected]:1415:Initialize:(IsFormatSampleRateAndChannelCountValid(inputHWFormat))] [avae] AVAu@R_502[email protected]:160引擎@ 0x2836a8940:无法初始化,错误= -10875 [avae] AVAEInternal.h:88必需条件为假:[AVAu@R_502[email protected]:1415:Initialize:(IsFormatSampleRateAndChannelCountValid(inputHWFormat))]

我也尝试过

au@R_502[email protected] (au@R_502[email protected],format: au@R_502[email protected] (forBus: 0))

au@R_502[email protected] (au@R_502[email protected],format: au@R_502[email protected] (forBus: 0))

在这两种情况下,应用程序因错误而崩溃 “由于未捕获的异常'com.apple.coreau@R_502[email protected]@R_502_6230@'而终止应用程序,原因:'所需条件为假:IsFormatSampleRateAndChannelCountValid(格式)”

解决方法

我发现问题在于必须将音频会话的类别playAndRecord

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

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

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