I am developing an application for iOS, and I need some audio processing methods so I employed AudioKit which is awesome. However I failed using AKNodeRecorder when trying recording the effects into audio file.
I have tried using the AudioKitPlayground(4.5.3) to test AKNodeRecorder, but got an empty audio file after recording the sound generated by the 'keyboard'.
So I create a project for iOS by Xcode(10.1), and add some Objective-C code like this:
........
NSError *error = nil;
AudioFormatID formatId = kAudioFormatLinearPCM;
NSDictionary *dict = @{
@"AVFormatIDKey" : @(formatId),
@"AVSampleRateKey" : @(44100),
@"AVNumberOfChannelsKey" : @(2),
};
AKAudioFile *audioFile = [[AKAudioFile alloc] initForWriting:soundFileURL settings:dict error:&error];
if (error) {
NSLog(@"AKAudioFile init error: %@", error);
}
AKNodeRecorder *akNodeRecorder = [[AKNodeRecorder alloc] initWithNode:self.akMixer file:audioFile error:&error];
if (error) {
NSLog(@"AKNodeRecorder init error: %@", error);
}
[akNodeRecorder recordAndReturnError:&error];
if (error) {
NSLog(@"recording error: %@", error);
}
[self.akAudioPlayer playFrom:0.0];
if (self.isChooseBackgroundMusic) {
[self.musicPlayer playFrom:0.0];
}
[akNodeRecorder stop];
........
And the self.akMixer here is like this:
self.akMixer = [[AKMixer alloc] init:@[self.akAudioPlayer, self.musicPlayer]];
But, I got am empty file too.
Is there something wrong in my code or I have misunderstood AKNodeRecorder? Any help? Many thanks!