iOS音频格式转换工具库:ExtAudioConverter

前段时间的工作,和iOS的音频相关,需要一个功能:将音频从wav格式转为mp3格式。这个需求不是很强,但却不太好实现。

于是我写了一个音频格式转换的开源库,这个库包含了iOS/OS X支持的所有音频格式,另外也支持mp3格式(使用lame实现)。它仿照OS X上的afconvert命令的参数设置,未来会比afconvert应用范围更大。

开源库名叫ExtAudioConverter,基于ExtAudioFile实现。链接在这里:https://github.com/lixing123/ExtAudioConverter

如何使用:

  1. 在项目里添加“AudioToolbox.framework”;
  2. 把”ExtAudioConverter.h”和”ExtAudioConverter.m”添加到项目;
  3. 测试:
        ExtAudioConverter* converter = [[ExtAudioConverter alloc] init];
        converter.inputFile =  @"/your/input/file";
        converter.outputFile = @"/your/output/file";
        [converter convert];

代码在iOS和OS X上测试通过。

一些可选的参数:
1. 采样率

converter.outputSampleRate = 44100;
  1. 声道数
converter.outputNumberChannels = 2;
  1. 位深
converter.outputBitDepth = BitDepth_16;
  1. 设置文件格式
converter.outputFileType = kAudioFileWAVEType;
  1. 设置数据格式
converter.outputFormatID = kAudioFormatLinearPCM;

关于文件格式和数据格式的说明文档,在这里:https://developer.apple.com/library/ios/documentation/MusicAudio/Conceptual/CoreAudioOverview/SupportedAudioFormatsMacOSX/SupportedAudioFormatsMacOSX.html

简单来讲,一种文件格式对应一种或者多种数据格式,如mp3 file format只对应mp3 data format,caf(Core Audio Format)格式则对应几乎所有data format。因此工具库默认的output file format就是caf格式。

现在还没有bit rate(比特率)的设置接口。后面将根据需要添加。

有需要的同学,可以下载用一下。如果有问题和建议,请
1. 跟我联系在此文章下评论;
2. 发送Issues到项目下面;
3. 发邮件到我的邮箱:shangwangwanwan@gmail.com

有github账号的同学,一个Star/Follow能鼓励我继续为开源社区作贡献,谢谢!

评论 18
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值