2016-07-29 136 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