How to save a recorded audio with reverb effect

2019-07-30 02:29发布

问题:

I am using theamazingaudioengine for recording, playing and adding effects like reverb for an iOS app. I can record, play the recorded audio along with the reverb effect. But I am unable to save audio file with the reverb effect to the gallery. Can any one please help me with this.

I am saving the recorded audio like this.

ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];

NSArray *documentsFolders = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = [[documentsFolders objectAtIndex:0] stringByAppendingPathComponent:@"Recording.aiff"];

[library writeVideoAtPathToSavedPhotosAlbum:[NSURL URLWithString:path] completionBlock:^(NSURL *assetURL, NSError *error){

    /*notify of completion*/

    NSLog(@"AssetURL: %@",assetURL);
    NSLog(@"Error: %@",error);

    if (!error) {
        //video saved

        [[self appDelegate] showAlertWithTitle:@"Audio Saved" message:@""];

    }
    else{

        [[self appDelegate] showAlertWithTitle:@"Error" message:error.domain];

    }

}];

Thanks in advance!

回答1:

The AEAudioFileWriter class allows you to easily write to any audio file format supported by the system.

To use it, instantiate it using initWithAudioDescription: , passing in the audio format you wish to use. Then, begin the operation by calling beginWritingToFileAtPath:fileType:error: , passing in the path to the file you'd like to record to, and the file type to use. Common file types include kAudioFileAIFFType, kAudioFileWAVEType, kAudioFileM4AType (using AAC audio encoding), and kAudioFileCAFType.

Once the write operation has started, you use the C functions AEAudioFileWriterAddAudio and AEAudioFileWriterAddAudioSynchronously to write audio to the file. Note that you should only use AEAudioFileWriterAddAudio when writing audio from the Core Audio thread, as this is done asynchronously in a way that does not hold up the thread.

When you are finished, call finishWriting to close the file.

More information...