小编Dee*_*hli的帖子

使用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];
}
Run Code Online (Sandbox Code Playgroud)

objective-c ios

12
推荐指数
1
解决办法
286
查看次数

标签 统计

ios ×1

objective-c ×1