繁体   English   中英

ios - 组合/连接多个音频文件

[英]ios - combine/concatenate multiple audio files

我有一堆音频文件(mp3、aac 等),我想将它们连接成 1 个音频文件。 以前有人这样做过吗?

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

请注意, AVAssetExportSession不会让您对文件输出进行太多控制(它会将音频导出到 m4a 文件中)。 如果您需要更多地控制输出类型,则需要使用AVAssetReaderAVAssetWriter类来执行导出而不是AVAssetExportSession 这些AVAssetExportSession使用起来复杂得多,在这里理解直接 C 是值得的。

我还要指出,没有 Apple 提供的选项来写出 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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM