1

I've successfully converted the AVAudioPCMBuffers from AVAudioEngine into AVAudioCompressedBuffers with an AAC format. Now I'm trying to write those buffers to a file but don't know how to do it. AVAudioFile only accepts AVAudioPCMBuffers.

Any help would be greatly appreciated!

4

2 回答 2

2

The easiest methods are to write to AVAudioFile before converting to compressed, or to convert back to PCM buffer and write to AVAudioFile.

If the easy methods are not an option, I believe you are stuck using Audio File Services. You would use the AVAudioCompressedBuffer's AudioBufferList property's data pointer as a the inBuffer argument to AudioFileWriteBytes. Interacting with the C API can get ugly fast, but it's the only way to write straight data to an audio file, short of doing it manually.

let data  = myAVAudioBufferlist.audioBufferList[0].mBuffers.mData
于 2018-04-25T19:41:15.700 回答
0

The easiest way I found was to convert the uncompressed AVAudioPCMBuffer to CMSampleBuffer and then use AVAssetWriter to write the audio samples to file. The asset writer can handle format compression to AAC.

I haven't tried this, but you can also probably use the audio buffer list from AVAudioCompressedBuffer and construct CMSampleBuffers.

于 2022-01-29T22:15:06.320 回答