how to change the pitch of recorded audio getting me following error

拜拜、爱过 提交于 2020-01-06 03:45:11

问题


Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: node != nil'

AVAudioFile *file=[[AVAudioFile alloc] initForReading:_recordedvoice error:nil];
AVAudioFormat *format=file.processingFormat;
AVAudioFrameCount capacity= (AVAudioFrameCount)file.length;
AVAudioPCMBuffer *buffer=[[AVAudioPCMBuffer alloc] initWithPCMFormat:format frameCapacity:capacity];
[file readIntoBuffer:buffer error:nil];
[playerNode scheduleBuffer:buffer completionHandler:nil];

engine = [[AVAudioEngine alloc] init];
    playerNode = [[AVAudioPlayerNode alloc] init];

[engine attachNode: playerNode];

AVAudioMixerNode *mixer = engine.mainMixerNode;
AVAudioUnitTimePitch *auTimePitch;
auTimePitch.pitch=1200.0;// In cents. The default value is 1.0. The range of values is -2400 to 2400
auTimePitch.rate = 2.0; //The default value is 1.0. The range of supported values is 1/32 to 32.0.

//get the error in the following line

[engine attachNode: auTimePitch];
[engine connect:playerNode to:auTimePitch format:[mixer outputFormatForBus:0]];
[engine connect:playerNode to:mixer format:[mixer outputFormatForBus:0]];

[playerNode play];

回答1:


Try starting the engine first before calling play:

[self.engine startAndReturnError:nil];
[playerNode play];


来源:https://stackoverflow.com/questions/38634069/how-to-change-the-pitch-of-recorded-audio-getting-me-following-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!