You need to add CoreAudio.framework to implement recording.
Also import following headers in .h file

AVFoundation/AVFoundation.h
CoreAudio/CoreAudioTypes.h

declare below in .h file itself      
       
       AVAudioRecorder * recorder;
	NSError * error;
       NSURL * recordedTmpFile;

Now add the following function in .m file to startRecording

-(void)StartRecording{
	//Record setting in MutableArray
	NSMutableDictionary* recordSetting = [[NSMutableDictionary alloc] init];
	[recordSetting setValue :[NSNumber numberWithInt:kAudioFormatAppleIMA4] forKey:AVFormatIDKey];
	[recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey]; 
	[recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];
	
	//Now that we have our settings we are going to instanciate an instance of our recorder instance.
	//Generate a temp file for use by the recording.
	recordedTmpFile = [NSURL fileURLWithPath:
					   [NSTemporaryDirectory() stringByAppendingPathComponent: 
						[NSString stringWithFormat:
						 @"Myrecording%d.%@",i++, @"caf"]]];
	NSLog(@"Using File called: %@",recordedTmpFile);
	//Setup the recorder to use this file and record to it.
	recorder = [[ AVAudioRecorder alloc] initWithURL:recordedTmpFile settings:recordSetting error:&error];
	//Use the recorder to start the recording.
	[recorder setDelegate:self];
	//We call this to start the recording process and initialize 
	[recorder prepareToRecord];
	//Start the actual Recording
	[recorder record];
}

To stop the recording and play add following function

-(void)StopRecording{
       [recorder stop];
       AVAudioPlayer * avPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:recordedTmpFile error:&error];
	[avPlayer prepareToPlay];
	[avPlayer play];
}

There is an optional method for doing the recording for a limited time see :

	[recorder recordForDuration:(NSTimeInterval) 10];

Incoming search terms:

  • iPad html5 Audio Recorder
  • RecordAudioiniPhone |SEO SEM Web eCommerce iOS Cloud HTML5 ChromeAppsandAndroid

Tagged with:

Filed under: iPhoneObjective C

Like this post? Subscribe to my RSS feed and get loads more!