在音频引擎输入节点上安装 Tap 时出错

mah*_*hdi 3 audio-recording ios swift avaudioengine avaudiofile

每当代码到达时 inputNode.installTap(onBus: 0, bufferSize: 1024, format: recordingFormat) {[weak self] (buffer:AVAudioPCMBuffer, when:AVAudioTime),应用程序就会因以下错误而崩溃

由于未捕获的异常“com.apple.coreaudio.avfaudio”而终止应用程序,原因:“所需条件为假:format.sampleRate == hwFormat.sampleRate”

在添加另一个之前,我已经厌倦了移除水龙头,并且我确保我不会添加多个水龙头。奇怪的是,该应用程序在低于 12 的 iOS 上运行良好,并且在所有模拟器上运行良好。

它仅在使用 iOS 12 的真实设备上崩溃。我尝试寻找解决方案但找不到任何东西。

dav*_*234 7

这是采样率不匹配。

输入节点的格式无法更改,因此您需要匹配它。installTap侦听节点的输出,因此使用 inputNode 的输出格式。

inputNode.installTap(onBus: 0, bufferSize: 1024, format: inputNode.outputFormat(forBus: 0))
Run Code Online (Sandbox Code Playgroud)

另一种选择是将输入连接到混音器,然后使用首选录音格式点击混音器。混频器在其输入和输出之间执行隐式采样率转换。