【问题标题】:poor sound quality while trying to record Audio in iPhone尝试在 iPhone 中录制音频时音质不佳
【发布时间】:2011-10-02 16:53:30
【问题描述】:

我正在使用 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;

谢谢..

【问题讨论】:

    标签: iphone ipad avaudioplayer avaudiorecorder avaudiosession


    【解决方案1】:

    使用此代码添加它。

    UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;     
    
                AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,          
                                         sizeof (audioRouteOverride),&audioRouteOverride);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-28
      • 1970-01-01
      • 1970-01-01
      • 2013-04-23
      • 1970-01-01
      • 2011-02-26
      相关资源
      最近更新 更多