[英]Real time Pitch Change while recording audio with AVAudioRecorder
I am trying to achieve functionality in which I can record a video and apply the effect over it in Real-time like an alien. 我正在尝试实现一种功能,我可以在其中录制视频并像实时外星人一样在实时中应用效果。 So that when I play it, will sound like the alien.
因此,当我演奏它时,听起来就像是外星人。
I have already achieved that I can change the pitch of the audio after recording the audio but now want to do it while recording the audio. 我已经实现了我可以在录制音频后改变音频的音高但是现在想要在录制音频时这样做。
Here is code for Recording audio with its settings. 以下是使用其设置录制音频的代码。
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];
}
Use AVCaptureAudioDataOutput
instead of AVAudioRecorder
, it allows you to handle audio data while it's being recorded: 使用
AVCaptureAudioDataOutput
代替AVAudioRecorder
,它允许您在录制时处理音频数据:
_captureAudioDataOutput = [[AVCaptureAudioDataOutput alloc] init];
[_captureAudioDataOutput setAudioSettings:recordSettings];
[_captureAudioDataOutput setSampleBufferDelegate:self queue:_dispatchQueue];
You need a AVCaptureSession
and self
must provide the function captureOutput
. 你需要一个
AVCaptureSession
并且self
必须提供函数captureOutput
。
In captureOutput
you can use the code you already have to change the audio pitch. 在
captureOutput
您可以使用已有的代码来更改音频音调。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.