我正在使用 AVAudioRecorder 类在我的应用程序中录制用户输入的语音。我能够录制和播放声音。但是,输出的质量非常低。尝试播放录制的音频时,我在背景中听到很多噪音。我应该怎么做才能获得高质量的音频输出。我正在使用以下设置(代码)来录制声音。
NSMutableDictionary *recordSetting = [[NSMutableDictionary alloc] init];
[recordSetting setValue:[NSNumber numberWithInt:kAudioFormatAppleLossless] forKey:AVFormatIDKey];
[recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey]; // previously i'v used 8400
[recordSetting setValue:[NSNumber numberWithInt:1] forKey:AVNumberOfChannelsKey];
以及以下用于播放音频的代码
[[AVAudioSession sharedInstance] setCategory:
AVAudioSessionCategoryPlayback error:NULL];
NSURL *fileTobePlayed = [NSURL fileURLWithPath:[[[[UIApplication sharedApplication]delegate] applicationDocumentsDirectory] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@",currentPage]]];
//AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:recordedTmpFile error:&error];
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:fileTobePlayed error:&error];
NSLog(@"The file being played is %@",fileTobePlayed);
[audioPlayer prepareToPlay];
[audioPlayer play];
audioPlayer.volume = 4.0;
谢谢..