4

我正在录制声音,然后更改音频的音高并保存。我在录制语音后调用此方法并单击按钮更改音高然后新文件也被创建但无法收听音频生成的音频没有语音可能是什么错误?

-(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];

}

4

0 回答 0