我正在开发我的应用程序中的录音功能。我正在使用这段代码:
-(void)startAudioRecorder:(NSError**)error{
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
NSError *err = nil;
[audioSession setCategory :AVAudioSessionCategoryPlayAndRecord error:&err];
if(err){
NSLog(@"audioSession: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
return;
}
[audioSession setActive:YES error:&err];
NSMutableDictionary* recordSetting = [[NSMutableDictionary alloc] init] ;
[recordSetting setValue :[NSNumber numberWithInt:kAudioFormatMPEG4AAC] forKey:AVFormatIDKey];//kAudioFormatAppleIMA4,kAudioFormatAAC
[recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey];
[recordSetting setValue:[NSNumber numberWithInt: 1] forKey:AVNumberOfChannelsKey];
NSString *absolutePath=[self getAbsoluteAudioFilePath];
if([[NSFileManager defaultManager] fileExistsAtPath:absolutePath]){
// [[NSFileManager defaultManager ] removeItemAtPath:absolutePath error:nil];
}
NSError *audioRecorderError=nil;
NSURL *absoluteUrl=[NSURL fileURLWithPath:absolutePath];
self.audioRecorder=[[[AVAudioRecorder alloc] initWithURL:absoluteUrl settings:recordSetting error:&audioRecorderError] autorelease];
NSLog(@"%s audioRecorder created=%@",__func__,self.audioRecorder);
[self.audioRecorder setDelegate: self];
BOOL prepared=[self.audioRecorder prepareToRecord];
BOOL record=[self.audioRecorder record];
if(!prepared || !record){
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"message" message:@"something wrong" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles: nil];
[alert show];
[alert release];
}
*error=audioRecorderError;
//[recordSetting release];
//recordSetting=nil;
}
从各种博客中,我找到了上面的录制代码,它在所有 iOS 设备上都按预期工作,我已经在 iPad、iPod 和 iPhone 上进行了测试。不幸的是,上面的代码在iPhone 4、iOS 5.1.1设备中以非常少的声音录制,其余所有组合都很好,我已经在语音备忘录中打开并录制了我的声音,同一硬件设备的 SpeakEasy 应用程序这两个应用程序运行良好,这意味着硬件运作良好。
是否有任何修改可以解决我的问题?录制高质量声音的最佳方法是什么?