在使用 AVFoundations 框架中的 AVAudioSession 和 AVAudioRecorder 录制时,我在尝试调整输入增益时遇到了一些问题。我找到了 setInputGain 方法,它接受一个浮点数 [0.0, 1.0],到目前为止,它看起来像这样:
在我看来DidLoad:
//Initialise the AVAudioSession, and share between different functions
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
[audioSession setActive:YES error:nil];
[audioSession setInputGain:1.0 error:nil];
但是,setInputGain 方法只会在当前录制的内容之上提供额外的增益,因此将其设置为 0.0 不会使其静音,但将其设置为 1.0 会使输入更响亮。我在 AudioSession 类中找到了一个名为 kAudioSessionProperty_InputGainScalar 的属性,但似乎无法将值写入其中。我需要一点帮助,拜托。
这是录音功能,后面有另一个教程:
//Creating a temporary place to record
tempRecFile = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"sound.caf"]];
recorder = [[AVAudioRecorder alloc] initWithURL:tempRecFile
settings:nil
error:nil];
[recorder setDelegate:self];
//Setting the input gain for the recording, then proceed to record
//[audioSession setInputGain:inputGainSlider.value error:nil];
[recorder prepareToRecord];
[recorder record];
[self.inputGainSlider setEnabled:NO];