AVAudioEngine录音崩溃, reason: ‘format.sampleRate == hwFormat.sampleRate

在使用AVAudioEngine进行录音时,应用程序出现崩溃,错误信息显示'format.sampleRate == hwFormat.sampleRate'。经过排查,发现是inputNode和mainMixerNode的采样率不一致导致的问题。原始代码中,inputFormat为48000 Hz,而outputFormat为44100 Hz。为了解决这个问题,将两个format的采样率都设置为48000 Hz,参考了https://gist.github.com/tad-iizuka/1ca07ca2045a8c6d11e22d15812f7e15的解决方案,修改后的代码解决了崩溃问题。
摘要由CSDN通过智能技术生成

AVAudioEngine录音频时偶发崩溃
报错信息大致如下:
2021-12-15 20:12:38.429028+0800 *[1659:708511] NSURLConnection finished with error - code -1002
"AudioRecorder 创建Audio缓存文件夹成功 /var/mobile/Containers/Data/Application/
/Library/Caches/Audio"
2021-12-15 20:13:30.762736+0800 ***[1659:708411] [avae] AVAEInternal.h:76 required condition is false: [AVAudioIONodeImpl.mm:1158:SetOutputFormat: (format.sampleRate == hwFormat.sampleRate)]
2021-12-15 20:13:30.764037+0800 ***[1659:708411] *** Terminating app due to uncaught exception ‘com.apple.coreaudio.avfaudio’, reason: ‘required condition is false: format.sampleRate == hwFormat.sampleRate’
*** First throw call stack:
(0x1989799d8 0x1accffb54 0x19888850c 0x1a88e2984 0x1a898c998 0x1a8923038 0x1a892945c 0x1a89a4f4c 0x1a899f414 0x10626bad4 0x10626b130 0x10627f8bc 0x10480ecc0 0x10480e8f4 0x10621e100 0x10621b720 0x10621dcf8 0x10480e8a0 0x10480ed20 0x19b1eaf38 0x19ab80184 0x19ab804c8 0x19ab7ee00 0x19ad65350 0x19ad634e0 0x19b2274cc 0x19b202b0c 0x19b285078 0x19b289818 0x19b280afc 0x1988f9bf0 0x1988f9af0 0x1988f8e38 0x1988f33e0 0x1988f2ba0 0x1af65b598 0x19b1e42f4 0x19b1e9874 0x1ac073b54 0x104a54194 0x104a5410c 0x104a5425c 0x1985d1568)
libc++abi.dylib: terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception ‘com.apple.coreaudio.avfaudio’, reason: ‘required condition is false: format.sampleRate == hwFormat.sampleRate’
terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception ‘com.apple.coreaudio.avfaudio’, reason: ‘required condition is false: format.sampleRate == hwFormat.sampleRate’
terminating with uncaught exception of type NSException

排查发现是inputNode和mainMixerNode的format不一致
(lldb) po inputFormat
<AVAudioFormat ***:

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值