【问题标题】:Convert Recorded sound in iphone from one format to another say wav to mp3将 iphone 中录制的声音从一种格式转换为另一种格式,例如 wav 到 mp3
【发布时间】: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 时,我都会收到此错误。现在请帮我解决这些问题。

  1. 我们可以使用 AudioToolbox 框架吗 和转换声音的功能 在压缩和非之间 压缩格式(目前我想要 在 .wav 和 .mp3 之间转换)。 在 AudioConverterNew 他们说的文件 "编码和解码之间 线性 PCM 和压缩格式是 支持”。但他们不是 具体说哪个压缩 格式。

  2. 如果问题 1 的答案是“否” 那么我需要哪个框架 用于在之间转换声音 上述格式?

  3. 与上述 2 无关,但可以 任何人给我一个链接到任何 提供有关信息的网站 不同的声音格式(wav、mp3、aac 等)及其数字 表示(cpm,lpcm 等)所以 我能理解哪些用途 什么。

【问题讨论】:

    标签: iphone mp3 wave audiotoolbox


    【解决方案1】:

    一些答案​​

    1. 是的,您可以使用 AudioToolbox 框架来转换声音,但 .mp3 格式除外。由于版权问题,mp3 不能作为框架内的目标格式。

    2. 如果您想转换为 mp3,您可能需要使用 LAME 库:http://lame.cvs.sourceforge.net/viewvc/lame/lame/USAGE

    3. 这是 .mp3 规范的一个:http://mpgedit.org/mpgedit/mpeg_format/MP3Format.html 您可以通过网络搜索轻松找到其他格式

    希望有帮助

    【讨论】:

      猜你喜欢
      • 2018-01-20
      • 2016-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多