我想用aac文件格式初始化AVAudioRecorder,但它不起作用......
以下代码有什么问题?
soundFilePath = [soundFilePath stringByAppendingPathExtension:@"aac"];
NSURL *url = [NSURL fileURLWithPath:soundFilePath isDirectory:FALSE];
NSMutableDictionary *recordSetting = [[NSMutableDictionary alloc] init];
[recordSetting setValue:[NSNumber numberWithInt: 'aac '] forKey:AVFormatIDKey]; //General Audio Format Settings
[recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey]; // "
[recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey]; // "
[recordSetting setValue:[NSNumber numberWithInt: 32] forKey:AVLinearPCMBitDepthKey]; //Linear PCM Format Settings
[recordSetting setValue:[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsBigEndianKey]; // "
[recordSetting setValue:[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsFloatKey]; // "
[recordSetting setValue:[NSNumber numberWithInt:AVAudioQualityLow] forKey:AVEncoderAudioQualityKey]; //Encoder Settings
[recordSetting setValue:[NSNumber numberWithInt:96] forKey:AVEncoderBitRateKey]; // "
[recordSetting setValue:[NSNumber numberWithInt:16] forKey:AVEncoderBitDepthHintKey]; // "
[recordSetting setValue:[NSNumber numberWithInt:AVAudioQualityLow] forKey:AVSampleRateConverterAudioQualityKey]; //Sample Rate Conversion Settings
_recorder = [[AVAudioRecorder alloc] initWithURL:url settings:recordSetting error:nil];
这个分配只返回nil ...
任何帮助将不胜感激......!
答案 0 :(得分:3)
删除有关PCM的每一行,并将formatIDKey
更改为
[NSNumber numberWithInt: kAudioFormatMPEG4AAC], AVFormatIDKey,
顺便说一下,使用m4a
作为扩展而不是aac
更合适,因为aac扩展用于MPEG2 AAC格式。
答案 1 :(得分:1)
iOS 5允许您录制到AAC。使用“kAudioFormatMPEG4AAC”为AVFormatIDKey尝试此操作。
答案 2 :(得分:0)
虽然您可以动态转换,但没有可以录制到AAC的设置:
答案 3 :(得分:-1)
[recordSetting setValue :[NSNumber numberWithInt:kAudioFormatMPEG4AAC_HE_V2] forKey:AVFormatIDKey];
这种格式是枚举。尝试查看枚举。 'aac'没有formatIDKey。它有aacp等。
答案 4 :(得分:-1)
只需使用以下设置在aac文件中录制人声。
recordSetting = [[NSMutableDictionary alloc] init];
[recordSetting setValue:[NSNumber numberWithInt:kAudioFormatAppleLossless] forKey:AVFormatIDKey];
[recordSetting setValue:[NSNumber numberWithFloat:44100.0] 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];