尝试在 iPhone 中录制音频时音质不佳
我正在使用 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;
谢谢..
I'm using AVAudioRecorder class for recording users input voice in my app. I am able to record and playback the sound. But, the quality of output is very low. I'm getting a lot of noise in the background while trying to playback the recorded audio. What should i do to get a rich quality audio output. I am using the following settings(code)to get the sound recorded.
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];
and the below code for playing the audio back
[[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;
Thanks..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用此代码来添加它。
Using this code to added it.