下载地址:https://github.com/hhuai/ios-util
在写AMR和WAV互转之前先说下使用AVAudioRecorder录音。
//AVAudioRecorder实现录音功能
NSMutableDictionary* recordSetting = [[NSMutableDictionaryalloc]init];
[recordSetting setValue :[NSNumbernumberWithInt:kAudioFormatAMR]forKey:AVFormatIDKey];
[recordSetting setValue:[NSNumbernumberWithFloat:44100.0]forKey:AVSampleRateKey];
[recordSetting setValue:[NSNumbernumberWithInt:2]forKey:AVNumberOfChannelsKey];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
recordFile = [NSURL fileURLWithPath:[documentsDirectory stringByAppendingPathComponent: [NSString stringWithFormat:@"test.%@",@"caf"]]];
m_Recorder = [[ AVAudioRecorder alloc] initWithURL:recordFile settings:recordSettings error:nil];
[m_RecordersetDelegate:self];
[m_RecorderprepareToRecord];
[m_Recorder record];
红色部分代码,设置合适的值,然后使用opencore-amr库在经一步进行编码解码。