2016-07-29 119 views
0

我已经找到了一个示例代码来录制AVAudioEngine &成功输出sampleRate 22050 aac格式的audioFile。使用AVAudioEngine,AVAudioSession setCategory AVAudioSessionCategoryRecord记录并重新采样aac格式?

我查看了代码后,出现了一个问题,我必须设置类AVAudioSessionCategoryPlayAndRecord而不是AVAudioSessionCategoryRecord。

How to improve the code for using "AVAudioSessionCategoryRecord" without "PlayAndRecord"?

(在这种情况下,我应该使用 “AVAudioSessionCategoryRecord” 吧?)

如果我setCategory到AVAudioSessionCategoryRecord,我得到一个错误:

AVAudioEngineGraph.mm:1070: Initialize: required condition is false: IsFormatSampleRateAndChannelCountValid(outputHWFormat)

Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: IsFormatSampleRateAndChannelCountValid(outputHWFormat)'

有一个关于使用麦克风的例子在AVAudioSessionCategoryRecord中,在我看来,我们只能用inputNode记录。 https://developer.apple.com/library/prerelease/content/samplecode/SpeakToMe/Introduction/Intro.html

以下代码现在可以工作。

关联链接

How can I specify the format of AVAudioEngine Mic-Input?

Recording audio file using AVAudioEngine

回答

0

AVAudioMixerNode不能够非压缩和压缩格式之间进行转换的。为此,您需要AVAudioConverter