iphone - 在 iphone 应用程序中录制用户语音时降低噪音?

标签 iphone objective-c avfoundation audio-recording

我正在尝试录制用户的声音,同时播放背景音乐。我可以使用 AVAudioSessionCategoryPlayAndRecord 设置 session 并同时播放背景和录音。但它记录了很多噪音,

有没有人知道如何降低噪音?

最佳答案

#define DOCUMENTS [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]
#define PATH_ARQUIVO [DOCUMENTS stringByAppendingPathComponent:@"gravacao.ma4"]



-(IBAction) recordAudio:(UIButton *)sender {

        NSURL* urlArquivo = [[NSURL alloc] initFileURLWithPath:PATH_ARQUIVO];

        NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys: 
        [NSNumber numberWithInt:AVAudioQualityMin], AVEncoderAudioQualityKey,
        [NSNumber numberWithInt:16], AVEncoderBitRateKey,
        [NSNumber numberWithInt:2], AVNumberOfChannelsKey, 
        [NSNumber numberWithFloat:44.1], AVSampleRateKey,
                                    nil];
        NSError* error;

        self.audioRecorder = [[AVAudioRecorder alloc] initWithURL:urlArquivo settings:dic error:&error];


        if (error) {
            NSLog(@"error: %@", [erro localizedDescription]);
        } else {
            //buffering
            [self.audioRecorder prepareToRecord];
            //recording
            [self.audioRecorder record];
        }
    }

    -(IBAction) stopRecorder:(UIButton *)sender {
        if ([self.audioRecorder isRecording]) {
            [self.audioRecorder stop];
        }
    }



    -(IBAction) PlayAudio:(UIButton *)sender {
        NSURL* urlArquivo = [[NSURL alloc] initFileURLWithPath:PATH_ARQUIVO];

        NSError* error;
        self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:urlArquivo error:&error];

        if (erro) {
            NSLog(@"error %@", [error localizedDescription]);
        } else {
            self.audioPlayer.numberOfLoops = HUGE_VALF;
            self.audioPlayer.enableRate = YES;
            [self.audioPlayer prepareToPlay];
            [self.audioPlayer play];
        }
    }

    -(IBAction) stopPlaying:(UIButton *)sender {
        if ([self.audioPlayer isPlaying]) {
            [self.audioPlayer stop];
        }
    }

    -(IBAction) changeRate:(UISlider *)sender {
        self.audioPlayer.rate = sender.value * 2; 
        /* it's a UISlider, max value = 1, min = 0 */
    }

关于iphone - 在 iphone 应用程序中录制用户语音时降低噪音?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8268070/

相关文章:

ios - Appium:启动Appium Inspector时,App连续崩溃

iphone - 没有接口(interface)的实例类或方法?

iphone - 如何实现正确的 uinavigationbar 后退按钮功能

ios - 使用 OpenGL ES 2.0 调整图像大小

ios - 如何在 swift 中将 View 设置为 UIViewController 的最大边界?

iphone - 在 UITabbar 项之间插入空格/ View /图像

ios - 调用 removeFromSuperlayer 后 CALayer 仍然显示

ios - 使用私有(private)方法使代码尽可能模块化

ios - 如何在 ios 中使用 Web 服务获取声音数据?

ios - NSTimer 没有正确传递参数?