iPhone SDK:在AVAudioPlayer中录制时,它也捕获背景噪音。任何人都可以帮我减少背景声音

时间:2015-08-19 05:17:00

标签: ios objective-c iphone audio-recording

我们正在设置这样的录音文件。

NSDictionary *settings = @{AVEncoderAudioQualityKey: @(AVAudioQualityMedium),
                               AVFormatIDKey: @(kAudioFormatMPEG4AAC),
                               AVEncoderBitRateKey: @(128000),
                               AVNumberOfChannelsKey: @(1),
                               AVSampleRateKey: @(44100)};

1 个答案:

答案 0 :(得分:0)

此代码适合我。

audioSettings = [NSDictionary dictionaryWithObjectsAndKeys:
                     [NSNumber numberWithFloat:44100],AVSampleRateKey,
                     [NSNumber numberWithInt:kAudioFormatMPEG4AAC],AVFormatIDKey,
                     [NSNumber numberWithInt:1],AVNumberOfChannelsKey,
                     [NSNumber numberWithInt:AVAudioQualityMedium],AVEncoderAudioQualityKey,nil];


AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];


AVAudioRecorder *recorder = [[AVAudioRecorder alloc] initWithURL:tempUrl settings:audioSettings error:&error];
recorder.delegate = self;
recorder.meteringEnabled = YES;
[recorder prepareToRecord];
[recorder record];