Initialization of AVAudioRecorder with aac
I want to initialize a AVAudioRecorder with a aac file format, but it doesnt work...
Whats wrong with the following code?
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 numberWithI开发者_JAVA技巧nt: 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];
this allocation just returns nil...
Any help will be appreciated...!
Remove every line about PCM, and change line with formatIDKey
to
[NSNumber numberWithInt: kAudioFormatMPEG4AAC], AVFormatIDKey,
Btw, it's more proper to use m4a
as an extension, rather than aac
, because aac extension was used for MPEG2 AAC format.
iOS 5 allows you to record to AAC. Try this using "kAudioFormatMPEG4AAC" for the AVFormatIDKey.
There are no settings to record to AAC, although you can convert on the fly:
https://github.com/michaeltyson/TPAACAudioConverter
[recordSetting setValue :[NSNumber numberWithInt:kAudioFormatMPEG4AAC_HE_V2] forKey:AVFormatIDKey];
The format for this is an enumeration. Try to look into the enumerations. There is no formatIDKey for 'aac' . It has aacp and others.
Just use following setting to record vocal in aac file.
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];
精彩评论