I work on voice recording, then change the pitch and save. I call this method after recording the voice and click on the button to change the pitch, and a new file is created, but I canβt listen to the sound from which the sound is generated without a voice, what could be an 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)
{
if (outputFile.length < _audioFile.length)
{
NSError *error;
NSAssert([outputFile writeFromBuffer:buffer error:&error], @"error writing buffer data to file, %@", [error localizedDescription]);
}else{
_audioEngine = nil;
[pitchEffect removeTapOnBus:0];
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];
}
source
share