How to record Audio in iOS Application Aasim Naseem, December 9, 2012 | Read Count: 13,480April 9, 2025 Category: My Tutorials > iOSHello dev mate; Hope you had a good weekend and refreshing Monday; Today we’ll learn how to record audio in iOS application; Now a days, I’m working on an application where I need to record voice of user for some processing; I tried some framework classes from iOS sdk in a test project and here are my findings; So lets start; Priminarly we’ll use following classes and framework AVFoundation.framwork Provides set of APIs to record/play audio and video in iOS application; AVAudioRecorder Called an audio recorder, provides audio recording capability in your application. AVAudioPlayer An instance of the AVAudioPlayer class called an audio player, provides playback of audio data from a file or memory; 1. Project Creation and Setup 1. Open you Xcode and create new project .i.e. File -> New -> New Project or press Command+Shift+N 2. Create Single View Application and provide suitable name; In my case, its AudioRecordingExample; 3. Select project location etc and save it; Your project should look like this 4. Add required framework to your project .i.e. AVFoundation; For this select your project in Navigator, then select Target at right sight panel; Go to Build Phases, chose Linke Binary with Libraries; Press + button from botom and chose AVFoundation from list; After adding framework, you libraries should look like this; 2. Interface Design First open the ViewController.xib file and make your screen like this; I’m sure I don’t need to explain how to design it; (: 3. Declaring Variable in .h file; Open you ViewController.h file from Navigator and add the following code there; Implement the following AVAudioRecorderDelegate and AVAudioPlayerDelegate in your viewController; @interface ViewController : UIViewController <AVAudioRecorderDelegate, AVAudioPlayerDelegate> Include AVFoundation.h in your import section; #import <AVFoundation/AVFoundation.h> Add the following two variables, and four UIButtons in your viewController; //for recording section AVAudioRecorder *audioRecorder; IBOutlet UIButton *recordingButton; IBOutlet UIButton *stopRecordingButton; //for playback section AVAudioPlayer *audioPlayer; IBOutlet UIButton *playButton; IBOutlet UIButton *stopPlayingButton; The name of variables are enough to describe their usage in our program; Bind the outlets with respective buttons on xib file; Now add following methods in your .h file -(IBAction) recordAudio; -(IBAction) stopRecording; -(IBAction) playAudio; -(IBAction) stopPlaying; 4. Your .m file, actual code Add the following code in your viewDidLoad method - (void)viewDidLoad { [super viewDidLoad]; audioRecorder.delegate = self; audioPlayer.delegate = self; playButton.enabled = NO; stopPlayingButton.enabled = NO; NSArray *dirPaths; NSString *docsDir; dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); docsDir = [dirPaths objectAtIndex:0]; NSString *soundFilePath = [docsDir stringByAppendingPathComponent:@"sound.caf"]; NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath]; 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]; if (error){ NSLog(@"error: %@", [error localizedDescription]); } else { [audioRecorder prepareToRecord]; } } Now add the action methods, bind with each UIButton over screen; -(IBAction) recordAudio{ if (!audioRecorder.recording){ playButton.enabled = NO; stopRecordingButton.enabled = YES; [audioRecorder record]; } } //------------------------------------------------------------------------------------------- -(IBAction)stopRecording{ stopRecordingButton.enabled = NO; playButton.enabled = YES; recordingButton.enabled = YES; if (audioRecorder.recording){ [audioRecorder stop]; } } //------------------------------------------------------------------------------------------- -(IBAction) stopPlaying{ if (audioPlayer.playing) { [audioPlayer stop]; } } //------------------------------------------------------------------------------------------- -(IBAction) playAudio{ if (!audioRecorder.recording){ stopPlayingButton.enabled = YES; recordingButton.enabled = NO; NSError *error; audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:audioRecorder.url error:&error]; audioPlayer.delegate = self; if (error) NSLog(@"Error: %@", [error localizedDescription]); else [audioPlayer play]; } } You can also implement these delegate methods, though to keep the tutorial simple, I’m not using them wisely here; -(void)audioPlayerDidFinishPlaying: (AVAudioPlayer *)player successfully:(BOOL)flag{ recordingButton.enabled = YES; stopPlayingButton.enabled = NO; } //------------------------------------------------------------------------------------------- -(void)audioPlayerDecodeErrorDidOccur:(AVAudioPlayer *)player error:(NSError *)error{ NSLog(@"Decode Error occurred"); } //------------------------------------------------------------------------------------------- -(void)audioRecorderDidFinishRecording: (AVAudioRecorder *)recorder successfully:(BOOL)flag{ NSLog(@"Audio Player has finished recording"); } //------------------------------------------------------------------------------------------- -(void)audioRecorderEncodeErrorDidOccur: (AVAudioRecorder *)recorder error:(NSError *)error{ NSLog(@"Encode Error occurred"); } //------------------------------------------------------------------------------------------- And we are good to go now; Just run the code, tap Record in recording section and speak something in your microphone; Hit stop and press Play in playback section; You’ll hear yourself for sure; The audio file has saved in /Document directory of your project, and you can get its content by following code, for further uses; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *filePath = [documentsDirectory stringByAppendingPathComponent:<your_file_name>]; NSData *fileContents = [NSData dataWithContentsOfFile:filePath]; Thats it; You have done infact; Now its time to look some new concepts; Back to code when we initialized our AVAudioRecorder instance, we provide it a dictionary of setting, as given below 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]; This dictionary is holding the different parameters for the audio we are going to capture and record; It inclues Bit rate, Sample rate, Number of channels etc; Let discuss them one by one in a concise way; Bit Rate Bitrate refers to the number of bits—or the amount of data—that are processed over a certain amount of time; In audio, this usually means kilobits per second; For example, if you have a song with bitrate of 256 kilobits per second, meaning there are 256 kilobits of data stored in every second of a song; Multiply the bitrate with length of your song and you’ll get the file size; The higher the bitrate of a track, the more space it will take up on your computer; Audio Channel A channel in audio is just one separate stream of audio information; Mono audio sources have one channel, Stereo sources have two (left and right), or in more simple words Mono is 1 audio channel (You hear the same sound in both ears) where as Stereo is 2 audio channels (Each headphone can hear a different sound) Now a days, the normally 5.1 audio channel are being use, having five normal audio channels (Left, Center, Right, Left Surround, Right Surround) Sample Rate Sample rate is the number of samples of audio carried per second; In simple words it is a frequency of audio; Data equal to bit rate is passed to processor to generate sample rates (audio frequency); More sample rate means more frequency and hence more clear, smooth audio listening experience; 44.1 kHz is the sampling rate of audio CDs giving a 20 kHz maximum frequency; 20 kHz is the highest frequency generally audible by humans, so making 44.1 kHz the logical choice for most audio material. Read the code again for initializing the AVAudioRecorder instance; Hope this time you’ll have better understanding; Happy coding; (: Author Profile Aasim Naseem Hey, Thanks for your interest. I’m a PMP, AWS Solutions Architect, and Scrum Master certified professional with 17+ years of hands-on experience leading projects, building teams, and helping organizations deliver software solutions better, faster, and smarter. Outside of work, I’ve got a deep curiosity for history — especially ancient civilizations like Egypt. I also enjoy reflecting on the everyday moments that shape how we live and work. This blog is my space to share insights, lessons, and thoughts from both my professional journey and personal interests. Thanks for reading — and I hope you will find something here that matches your interest. Latest entries IslamJune 6, 2025 | Read Count: 283Economic impact of Eid-ul-Adha PMP CertificationMay 23, 2025 | Read Count: 493Best PMP Study Resources for 2025 (Books, Courses, Tools & More) Agile & FrameworksMay 7, 2025 | Read Count: 463Agile vs Scrum: Finally Understanding the Difference Agile & FrameworksApril 25, 2025 | Read Count: 493When Not To Use Agile: 5 Signs You Need a Different Approach iOS AVAudioPlayerAVAudioRecorderAVFoundationhow to recored audio in iphoneiPhonevoice recordingxcode
iOS Beta Builder :: Wireless Distribution of Your Adhoc Archive June 5, 2013 | Read Count: 12,472April 9, 2025 Category: My Tutorials > iOS Hey .. how’s work going? It’s good Han !!! … good good … So you have done with your release and verified with QA after some bug fixing; That’s great; You done a good job; Now Its time to share the Adhoc with client; Ok… Read More
iOS Not enough frames in Stack – iO| January 10, 2011 | Read Count: 14,500May 5, 2025 Category: My Tutorials > iOSIf you are getting this error message in your console while running your app on iPhone/iPod (specially on 1G, having ios < 3.2) dyld: Symbol not found: _OBJC_CLASS_$_UIPopoverController Referenced from: /var/mobile/Applications/5BC198AF-22AF-4581-8787-E267D359E059/FilesAnyWhere.app/<your_app_name> Expected in: /System/Library/Frameworks/UIKit.framework/UIKit in /var/mobile/Applications/5BC198AF-22AF-4581-8787-E267D359E059/FilesAnyWhere.app/<your_app_name> <em>Data Formatters temporarily unavailable, will re-try after a 'continue'. (Not… Read More
iOS How to symbolicate iPhone Crash Reports; May 10, 2011 | Read Count: 14,453May 5, 2025 Category: My Tutorials > iOSHello Everyone; Hows your developments going? Im sure you enjoy it as much as i do; Its really a fun; Today’s menu is related to iPhone Applications; We often notice that iPhone/iPod/iPad applications hangup or exit abnormally; It means the running application has been crashed due to some… Read More
Such a nice code… Thanks for Your great Help… keep post like advanced things with more explanations Reply
Great tute, was just wondering how would we save audios permanently and display it in table view so one can go back to it later and play it? Thanks Reply
Can you please elaborate your requirements bit more? How your screen look like, and how do you want to save audios in TableView? Reply
Good web site you’ve got here.. It’s difficult to find high quality writing like yours these days. I honestly appreciate individuals like you! Take care!! Reply