Return to Snippet

Revision: 37409
at December 9, 2010 19:30 by vaishnavi


Initial Code
-(void) mic{

	[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error: nil];
	time=0;
	
	NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
	NSString *documentsDirectory = [paths objectAtIndex:0];
	NSDate *now = [NSDate dateWithTimeIntervalSinceNow:0];
	NSString *caldate = [now description];
	NSString *recorderFilePath = [[NSString stringWithFormat:@"%@/%@.caf", documentsDirectory, caldate] retain];
	
	NSURL *url = [NSURL fileURLWithPath:recorderFilePath];
	NSDictionary *settings = [NSDictionary dictionaryWithObjectsAndKeys:
							  [NSNumber numberWithFloat: 44100.0],                 AVSampleRateKey,
							  [NSNumber numberWithInt: kAudioFormatAppleLossless], AVFormatIDKey,
							  [NSNumber numberWithInt: 1],                         AVNumberOfChannelsKey,
							  [NSNumber numberWithInt: AVAudioQualityMax],         AVEncoderAudioQualityKey,
							  nil];
	
	NSError *error;
	
	recorder = [[AVAudioRecorder alloc] initWithURL:url settings:settings error:&error];
	
	if (recorder) {
		[recorder prepareToRecord];
		recorder.meteringEnabled = YES;
		[recorder record];
		levelTimer = [NSTimer scheduledTimerWithTimeInterval: 0.03 target: self selector: @selector(levelTimerCallback:) userInfo: nil repeats: YES];
	}
}

- (void)levelTimerCallback:(NSTimer *)t {
	[recorder updateMeters];
	isTimerValid=YES;
	if([recorder averagePowerForChannel:0]>-25){
	//record in progress
        }	
}

Initial URL

                                

Initial Description

                                

Initial Title
Record sound in iPhone

Initial Tags

                                

Initial Language
Objective C