ios - 组合/连接多个音频文件 [英] ios - combine/concatenate multiple audio files
问题描述
我有一堆音频文件(mp3,aac,等等),我想将它们连接成1个音频文件。有没有人以前做过这个?
I have a bunch of audio files (mp3, aac, whatever) and I want to concatenate them into 1 audio file. Has anyone done this before?
推荐答案
我做到了这一点。要进行连接,首先需要将音频文件加载到 AVAssets 的。具体来说,您将要使用名为 AVURLAssets ,可以加载您的网址:加载AVAsset 。然后,您可以将每个 AVAsset
添加到 AVMutableComposition ,旨在包含多个 AVAssets
。一旦你将它加载到 AVMutableComposition
,你可以使用 AVAssetExportSession 将合成写入文件。
I have done this. To do the concatenation you first need to load the audio files into AVAssets. Specifically, you'll want to use a subclass of AVAsset called AVURLAssets, which can load up your URL: Loading AVAsset. You can then add each AVAsset
into a AVMutableComposition, which is designed to contain multiple AVAssets
. Once you've gotten it loaded into AVMutableComposition
, you can use AVAssetExportSession to write the composition to a file.
注意 AVAssetExportSession
不会让您对文件输出有太多控制权(它会将音频导出到m4a文件中)。如果您需要更多地控制输出类型,则需要使用 AVAssetReader 和 AVAssetWriter 类执行导出而不是 AVAssetExportSession
。使用这些类比 AVAssetExportSession
要复杂得多,这里需要了解直接C。
Note that AVAssetExportSession
doesn't give you much control over the file output (it'll export audio into a m4a file). If you need more control over the type of output, you'll need to use the AVAssetReader and AVAssetWriter classes to perform the export rather than the AVAssetExportSession
. These classes are much more complex to use than AVAssetExportSession
and it pays here to understand straight C.
我也会指出没有Apple提供的选项来写出MP3文件。你可以阅读它们,但你不能写它们。通常最好坚持使用m4a / aac格式。
I will also point out that there are no Apple-provided options to write out MP3 files. You can read them, but you can't write them. It's generally best to stick with a m4a/aac format.
这篇关于ios - 组合/连接多个音频文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!