I use AVAudioRecorder to capture microphone sound. The problem I am facing is this: the first time I start recording, there is a 2 second delay between when I say that the recording device starts and when it really starts. Subsequent recording calls are much faster. Are there any obvious errors here? What can I do to speed up the 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 started the recorder by calling the startRecoring method:
-(void) startRecording{ NSLog(@"Trying to start Recording"); [audioRecorder record]; NSLog(@"Recording started"); }
Here is the output of the log, and you can see that there is approximately 2.5 seconds between two calls to NSLog. First time click, but not another time:
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
source share