How to save the audio recorded with pitch changed?

情到浓时终转凉″ 提交于 2019-12-07 08:00:44

问题


I'm working on recording the voice then change the pitch of the audio and save. I call this method after recording the voice and click on the button to change the pitch then the new file is also created but the not not able to listen the audio the audio is generated with out voice what may be the error?

-(void)saveEffectedAudioToFolder

{
NSError *error;
if (_audioEngine) {


    AVAudioUnitTimePitch *pitchEffect = [AVAudioUnitTimePitch new];



    pitchEffect.pitch = pitch;


    AVAudioFormat  * commonFormat = [[AVAudioFormat alloc] initWithCommonFormat:AVAudioPCMFormatFloat32 sampleRate:44100 channels:2 interleaved:NO];

    //
    AVAudioFile *outputFile = [[AVAudioFile alloc] initForWriting:[NSURL URLWithString:_filePathDstaud] settings:commonFormat.settings error:&error];

    if (error) {
        NSLog(@"Error is 1 %@",[error localizedDescription]);


    }


    [pitchEffect installTapOnBus: 0 bufferSize: 8192 format: commonFormat block: ^(AVAudioPCMBuffer *buffer, AVAudioTime *when)
     //here is that error 
     {

         if (outputFile.length < _audioFile.length)
         {
             //Let us know when to stop saving the file, otherwise saving infinitely
             NSError *error;

             NSAssert([outputFile writeFromBuffer:buffer error:&error], @"error writing buffer data to file, %@", [error localizedDescription]);

         }else{
             _audioEngine = nil;
             [pitchEffect removeTapOnBus:0];//if we dont remove it, will keep on tapping infinitely
             NSLog(@"Did you like it? Please, vote up for my question");
         }

     }


     ];
}
NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];

NSString *filePath = [documentsPath stringByAppendingPathComponent:name];

[fileManager removeItemAtPath:filePath error:&error];

}

来源:https://stackoverflow.com/questions/39080185/how-to-save-the-audio-recorded-with-pitch-changed

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