我正在尝试录制一些音频并将它们转换为其他声音格式。我正在使用 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,我就会收到此错误。现在请帮我解决这些问题。
我们可以使用AudioToolbox框架和函数在压缩和非压缩格式之间转换声音(目前我想在.wav和.mp3之间转换)。在 AudioConverterNew 文档中,他们说“支持线性 PCM 和压缩格式之间的编码和解码”。但他们并没有具体说明哪些压缩格式。
如果问题 1 的答案是“否”,那么我需要使用哪个框架在上述格式之间转换声音?
- 与上述 2 无关,但任何人都可以给我一个链接到任何网站的链接,其中包含有关不同声音格式(wav、mp3、aac 等)及其数字表示(cpm、lpcm 等)的信息,以便我了解哪个使用什么。