[英]Real time Pitch Change while recording audio with AVAudioRecorder
我正在尝试实现一种功能,我可以在其中录制视频并像实时外星人一样在实时中应用效果。 因此,当我演奏它时,听起来就像是外星人。
我已经实现了我可以在录制音频后改变音频的音高但是现在想要在录制音频时这样做。
以下是使用其设置录制音频的代码。
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
您可以使用已有的代码来更改音频音调。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.