【发布时间】:2011-04-15 02:09:20
【问题描述】:
我正在尝试录制一些音频并将它们转换为其他声音格式。我正在使用 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 等)所以 我能理解哪些用途 什么。
【问题讨论】:
标签: iphone mp3 wave audiotoolbox