I'm using the following code to record with AVAudioRecorder. I'm also accessing the recorded audio live (after 4 seconds) as well. However, the data is NULL until 6 seconds.
Is there a way to forcefully ask the recorder to write to file?
NSDictionary * recordSetting;
recordSetting = [[NSMutableDictionary alloc] init];
[recordSetting setValue :[NSNumber numberWithInt:kAudioFormatMPEG4AAC] forKey:AVFormatIDKey];
[recordSetting setValue:[NSNumber numberWithFloat:11025] forKey:AVSampleRateKey];
[recordSetting setValue:[NSNumber numberWithInt:1] forKey:AVNumberOfChannelsKey];
self.fileURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/recorded.aac", [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]]];
self.recorder = [[AVAudioRecorder alloc] initWithURL:self.fileURL settings:recordSetting error:nil];
self.recorder.meteringEnabled = YES;
self.recorder.delegate = self;
[self.recorder record];
And then after 4 seconds, I tried to read the file using NSDate.
NSData *songData = [NSData dataWithContentsOfURL:self.recorder.url];
But the songData is nil until after 6 seconds.
I know it's possible to do so using AudioQueue, however, I do not wish to get into AudioQueue because I guess it would be an overkill.
Thanks.