我正在尝试录制一些音频,并将它们转换成其他声音格式。我使用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];
录音效果很好。现在我想把这个声音文件转换成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()给出了错误kAudioConverterErr_FormatNotSupported ('fmt')。我尝试了不同的mFormatID和mFormatFlag组合。但是,每当操作者(源或目标)之一是mp3时,我就会得到这个错误。现在请帮我回答这些问题。
。
发布于 2012-07-02 13:15:48
一些答案
找到
希望这有帮助
https://stackoverflow.com/questions/3758618
复制相似问题