xPr*_*mer 5 iphone mp3 wave audiotoolbox
我正在尝试录制一些音频并将其转换为其他声音格式.我正在使用AVAudioRecorder类进行录制,这些是我使用的录制设置.
NSDictionary *recordSetting = [[NSMutableDictionary alloc] init];
[recordSetting setValue:[NSNumber numberWithInt:kAudioFormatLinearPCM] forKey:AVFormatIDKey];//kAudioFormatMicrosoftGSM,kAudioFormatLinearPCM
[recordSetting setValue:[NSNumber numberWithFloat:8000] forKey:AVSampleRateKey];
[recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];
[recordSetting setValue :[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
[recordSetting setValue :[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsBigEndianKey];
[recordSetting setValue :[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsFloatKey];
Run Code Online (Sandbox Code Playgroud)
录音工作得很漂亮.现在我想将此声音文件转换为mp3格式.我可以使用AudioToolBox框架执行此操作.我试过这个
AudioStreamBasicDescription sourceFormat,destinationFormat;
//Setting up source Format setting..here wav
sourceFormat.mSampleRate = 8000.0;
sourceFormat.mFormatID = kAudioFormatLinearPCM;
sourceFormat.mFormatFlags = kAudioFormatFlagIsSignedInteger ;
sourceFormat.mBytesPerPacket = 4;
sourceFormat.mFramesPerPacket = 1;
sourceFormat.mBytesPerFrame = 4;
sourceFormat.mChannelsPerFrame = 2;
sourceFormat.mBitsPerChannel = 16;
destinationFormat.mSampleRate = 8000.0;
destinationFormat.mFormatID = kAudioFormatMPEGLayer3;
destinationFormat.mFormatFlags = 0;
destinationFormat.mBytesPerPacket = 4;
destinationFormat.mFramesPerPacket = 1;
destinationFormat.mBytesPerFrame = 4;
destinationFormat.mChannelsPerFrame = 2;
destinationFormat.mBitsPerChannel = 16;
OSStatus returnCode = AudioConverterNew(&sourceFormat,&destinationFormat,&converter);
if (returnCode) {
NSLog(@"error getting converter : %d",returnCode);
return;
}
Run Code Online (Sandbox Code Playgroud)
AudioConverterNew()函数给我错误kAudioConverterErr_FormatNotSupported('fmt').我尝试了不同的mFormatID和mFormatFlag组合.但只要其中一个操作符(源或目标)是mp3我就会收到此错误.现在请帮我解决这些问题.
我们可以使用AudioToolbox框架和函数来转换压缩和非压缩格式之间的声音(目前我想在.wav和.mp3之间进行转换).在AudioConverterNew文档中,他们说"支持线性PCM和压缩格式之间的编码和解码".但他们没有具体说明哪种压缩格式.
如果对问题1的回答为"否",那么我需要使用哪个框架来转换上述格式之间的声音?
小智 1
一些答案
是的,您可以使用 AudioToolbox 框架来转换声音,但 .mp3 格式除外。由于版权问题,mp3 不能作为框架内的目标格式。
如果您想转换为 mp3,您可能需要使用 LAME 库:http://lame.cvs.sourceforge.net/viewvc/lame/lame/USAGE
以下是 .mp3 规范:http://mpgedit.org/mpgedit/mpeg_format/MP3Format.html 您可以通过网络搜索轻松找到其他格式
希望有帮助