AVAudioRecorder支持哪些格式录制声音?

时间:2011-07-29 02:16:57

标签: ios avaudiorecorder avaudiosession

我在http://developer.apple.com/library/ios/#documentation/MusicAudio/Reference/CoreAudioDataTypesRef/Reference/reference.html#//apple_ref/doc/uid/TP40004488

找到了不同值(音频数据格式)的列表

音频数据格式标识符 音频数据格式的标识符,用于AudioStreamBasicDescription结构。

kAudioFormatLinearPCM ='lpcm',

kAudioFormatAC3 ='ac-3',

kAudioFormat60958AC3 ='cac3',

kAudioFormatAppleIMA4 ='ima4',

kAudioFormatMPEG4AAC ='aac',

kAudioFormatMPEG4CELP ='celp',

kAudioFormatMPEG4HVXC ='hvxc',

kAudioFormatMPEG4TwinVQ ='twvq',

kAudioFormatMACE3 ='MAC3',

kAudioFormatMACE6 ='MAC6',

kAudioFormatULaw ='ulaw',

kAudioFormatALaw ='alaw',

kAudioFormatQDesign ='QDMC',

kAudioFormatQDesign2 ='QDM2',

kAudioFormatQUALCOMM ='Qclp',

kAudioFormatMPEGLayer1 ='。mp1',

kAudioFormatMPEGLayer2 ='。mp2',

kAudioFormatMPEGLayer3 ='。mp3',

kAudioFormatTimeCode ='time',

kAudioFormatMIDIStream ='midi',

kAudioFormatParameterValueStream ='apvs',

kAudioFormatAppleLossless ='alac'

kAudioFormatMPEG4AAC_HE ='aach',

kAudioFormatMPEG4AAC_LD ='aacl',

kAudioFormatMPEG4AAC_ELD ='aace',

kAudioFormatMPEG4AAC_HE_V2 ='aacp',

kAudioFormatMPEG4AAC_Spatial ='aacs',

kAudioFormatAMR ='samr',

kAudioFormatAudible ='AUDB',

kAudioFormatiLBC ='ilbc',

kAudioFormatDVIIntelIMA = 0x6D730011,

kAudioFormatMicrosoftGSM = 0x6D730031,

kAudioFormatAES3 ='aes3'

但是,我不认为我们可以使用所有提到的格式(例如mp3)。

任何人都可以帮我解决使用AVAudioRecorder录制声音所支持的格式吗?

感谢。

2 个答案:

答案 0 :(得分:10)

根据苹果文档Apple Core Audio Format Specification 1.0它现在应该支持mp3,虽然我还没有测试过,这是他们支持的当前枚举:

enum {
    kAudioFormatLinearPCM      = 'lpcm',
    kAudioFormatAppleIMA4      = 'ima4',
    kAudioFormatMPEG4AAC       = 'aac ',
    kAudioFormatMACE3          = 'MAC3',
    kAudioFormatMACE6          = 'MAC6',
    kAudioFormatULaw           = 'ulaw',
    kAudioFormatALaw           = 'alaw',
    kAudioFormatMPEGLayer1     = '.mp1',
    kAudioFormatMPEGLayer2     = '.mp2',
    kAudioFormatMPEGLayer3     = '.mp3',
    kAudioFormatAppleLossless  = 'alac'
};

答案 1 :(得分:0)

上面列出

  

当前为mFormatID字段定义的值

不支持录制。

使用AVAudioRecorder格式进行测试(带采样率):

"MPEG4AAC (8000, 11025, 22050, 32000, 44100, 48000)",
"AppleLossless (8000, 11025, 22050, 32000, 44100, 48000)",
"MPEG4AAC_HE (32000, 44100, 48000)",
"MPEG4AAC_LD (22050, 32000, 44100, 48000)",
"MPEG4AAC_ELD (22050, 32000, 44100, 48000)",
"MPEG4AAC_ELD_SBR (22050, 32000, 44100, 48000)",
"MPEG4AAC_ELD_V2 (22050, 32000, 44100, 48000)"

示例:

[[AVAudioRecorder alloc] initWithURL:outputFileURL
                            settings:@{
                                       AVFormatIDKey : @(kAudioFormatMPEG4AAC),
                                       AVSampleRateKey : @(44100.0),
                                       AVNumberOfChannelsKey : @(2)
                                       }
                               error:&error];

Supported Audio file formats