尝试在 iPhone 中录制音频时音质不佳

发布于 2024-11-19 05:02:11 字数 1259 浏览 2 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

那一片橙海, 2024-11-26 05:02:11

使用此代码来添加它。

UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;     

            AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,          
                                     sizeof (audioRouteOverride),&audioRouteOverride);

Using this code to added it.

UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;     

            AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,          
                                     sizeof (audioRouteOverride),&audioRouteOverride);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文