ios – 合并/连接多个audio文件

我有一堆audio文件(MP3,AAC,无论),我想将它们连接成1个audio文件。 有没有人做过这个?

我已经这样做了。 要进行连接,首先需要将audio文件加载到AVAsset中 。 具体来说,您需要使用名为AVURLAssets的AVAsset的子类,它可以加载您的URL: 加载AVAsset 。 然后,您可以将每个AVAsset添加到AVMutableComposition中 , AVMutableComposition被devise为包含多个AVAssets 。 一旦将它加载到AVMutableComposition ,您可以使用AVAssetExportSession将组合写入文件。

请注意, AVAssetExportSession不会给你太多的文件输出控制(它会将audio导出到m4a文件中)。 如果您需要对输出types进行更多的控制,则需要使用AVAssetReader和AVAssetWriter类来执行导出,而不是AVAssetExportSession 。 这些AVAssetExportSession使用起来要复杂得多,并且在这里了解直线C.

我也会指出,没有苹果提供的选项来写出MP3文件。 你可以阅读,但你不能写。 通常最好坚持使用m4a / aac格式。

使用ExtAudioFile这非常简单。 伪代码你想要做的是:

 1. Open the file you'll be using for output (ExtAudioFileOpen) 2. Set the client data format you'll use for ExtAudioFileWrite 3. For each input file you want to process: a. Open the file using ExtAudioFile b. Set the client data format used for reading to the same client format used in the output file for writing c. Loop through the input file using ExtAudioFileRead and save the data to the output file using ExtAudioFileWrite d. Close the input file 4. Close the output file