我正在尝试实现可以录制视频并实时应用效果的功能,就像外星人一样。这样当我播放它时,听起来就像是外星人。
我已经实现了可以在录制音频后更改音频的音调,但现在想在录制音频时进行更改。
这是录制音频及其设置的代码。
NSString *docsDir;
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = dirPaths[0];
NSString *soundFilePath = [docsDir stringByAppendingPathComponent:@"sound.caf"];
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
NSDictionary *recordSettings = [NSDictionary
dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:AVAudioQualityMin],
AVEncoderAudioQualityKey,
[NSNumber numberWithInt:16],
AVEncoderBitRateKey,
[NSNumber numberWithInt: 2],
AVNumberOfChannelsKey,
[NSNumber numberWithFloat:44100.0],
AVSampleRateKey,
nil];
NSError *error = nil;
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
_audioRecorder = [[AVAudioRecorder alloc]
initWithURL:soundFileURL
settings:recordSettings
error:&error];
_audioRecorder.delegate = self;
_audioRecorder.meteringEnabled = YES;
if (error) {
NSLog(@"error: %@", [error localizedDescription]);
} else {
[_audioRecorder prepareToRecord];
}
最佳答案
使用AVCaptureAudioDataOutput
代替 AVAudioRecorder
,它允许您在录制时处理音频数据:
_captureAudioDataOutput = [[AVCaptureAudioDataOutput alloc] init];
[_captureAudioDataOutput setAudioSettings:recordSettings];
[_captureAudioDataOutput setSampleBufferDelegate:self queue:_dispatchQueue];
你需要一个 AVCaptureSession
并且 self
必须提供函数 captureOutput
.
在 captureOutput
中,您可以使用已有的代码来更改音频音调。
关于ios - 使用 AVAudioRecorder 录制音频时的实时音高变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49894548/