在目标c中将两个音频文件合二为一 [英] Combine two audio files into one in objective c

查看:26
本文介绍了在目标c中将两个音频文件合二为一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
合并iPhone上的音频文件

我正在尝试将 2 个音频文件合并为一个文件.例如:file1.mp3 - 它说我是".file2.mp3 - 它说乔治".我想得到一个组合文件 file3.mp3,上面写着我是乔治".

I'm trying to combine 2 audio files into one file. For example: file1.mp3 - it says "I am". file2.mp3 - it says "George". I want to get a combined file file3.mp3 which will say "I am George".

如何在 Objective-C 中做到这一点?

How can I do this in objective-C?

推荐答案

看看 AVFoundation 框架...有很多方法,但最简单的一种可以是...

Look at AVFoundation framework ... There're many ways, but the simplest one for you can be ...

  • 为这两个文件创建 AVAsset(使用 AVURLAsset 子类),
  • alloc AVMutableComposition (composition),
  • 将类型为 AVMediaTypeAudioAVMutableCompositionTrack 添加到 composition
  • create AVAsset for both files (use AVURLAsset subclass),
  • alloc AVMutableComposition (composition),
  • add AVMutableCompositionTrack with type AVMediaTypeAudio to composition

[composition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid];

  • 从第一个 AVAsset 中获取音轨并添加它AVMutableCompositionTrack
  • 从第二个 AVAsset 获取轨道并将其附加到 AVMutableCompositionTrack
  • 然后使用您的作品创建 AVAssetExportSession 并将其导出.
  • get track(s) from the first AVAsset and add it AVMutableCompositionTrack,
  • get track(s) from the second AVAsset and append it to AVMutableCompositionTrack,
  • then create AVAssetExportSession with your composition and export it.

简单的描述,但你得到了一个线索.取决于你有多少音轨,你想使用什么样的效果等等.

Simplified description, but you get a clue. Depends on how many tracks do you have, what kind of effects do you want to use, etc.

如果您确实想查看一些真实的代码,请打开 AVMovieExporter 示例,复制此代码并删除视频内容并只保留音频.

If you do want to see some real code, open AVMovieExporter example, copy this code and remove video stuff and leave audio there only.

这篇关于在目标c中将两个音频文件合二为一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆