将iphone中录制的声音从一种格式转换为另一种格式,如wav转换为mp3
我正在尝试录制一些音频并将其转换为其他声音格式。我正在使用AVAudioRecorder类进行录制,这些是我使用的录制设置将iphone中录制的声音从一种格式转换为另一种格式,如wav转换为mp3,iphone,mp3,wave,audiotoolbox,Iphone,Mp3,Wave,Audiotoolbox,我正在尝试录制一些音频并将其转换为其他声音格式。我正在使用AVAudioRecorder类进行录制,这些是我使用的录制设置 NSDictionary *recordSetting = [[NSMutableDictionary alloc] init]; [recordSetting setValue:[NSNumber numberWithInt:kAudioFormatLinearPCM] forKey:AVFormatIDKey];//kAudioFormatMicrosoftGSM,
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];
录音效果很好。现在我想把这个声音文件转换成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;
}
函数AudioConverterNew()给了我错误kaudioconverterner\u FormatNotSupported('fmt')。我尝试了不同的mFormatID和mFormatFlag组合。但每当一个操作(源或目标)是mp3时,我就会得到这个错误。现在请帮我回答这些问题