I'm using the AVAudioRecorder to grab audio from the microphone. The problem i'm facing is this: the first time I start recording there is a 2 second delay between when I tell the recorder to start and when it actually starts. Subsequent recording calls execute much quicker. Are there any obvious bugs here? What can I do to speed up time it takes to start the initial recording.
I initialized the recorder in viewDidLoad:
- (void)viewDidLoad
{
NSString *fileName = @"test.aiff";
[super viewDidLoad];
NSString *docsDir = [NSSearchPathForDirectoriesInDomains(
NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *soundFile = [docsDir
stringByAppendingPathComponent:fileName];
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFile];
NSDictionary *recordSettings = [NSDictionary
dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:AVAudioQualityMin],
AVEncoderAudioQualityKey,
[NSNumber numberWithInt:16],
AVEncoderBitRateKey,
[NSNumber numberWithInt: 2],
AVNumberOfChannelsKey,
[NSNumber numberWithFloat:44100.0],
AVSampleRateKey,
nil];
NSError *error = nil;
audioRecorder = [[AVAudioRecorder alloc]
initWithURL:soundFileURL
settings:recordSettings
error:&error];
}
Then when I'm ready i start the recorder by calling my startRecoring method:
-(void) startRecording{
NSLog(@"Trying to start Recording");
[audioRecorder record];
NSLog(@"Recording started");
}
Here is the Log output and you can see that there is roughly 2.5 seconds between the two NSLog calls. On the first time clicked but not other times:
First recorder call
2011-04-13 15:41:47.495 AudioRecorderTest[6570:207] Trying to start Recording
2011-04-13 15:41:49.869 AudioRecorderTest[6570:207] Recording started
Next Recorder Call
2011-04-13 15:42:49.236 AudioRecorderTest[6570:207] Trying to start Recording
2011-04-13 15:42:49.246 AudioRecorderTest[6570:207] Recording started