views:

281

answers:

1

I am developing an iPhone voice recording application which creates audio files in caf format.

When I play those files back, the only thing I here is static. Also, the sizes of the files are huge e.g. up to 1.7 mb for a 10 sec recording.

Could I record in another format such as mp3. Does anyone have some example code of how to do so?

thanks

A: 

You have to use AVAudioRecorder class to do that. Here is a link to developer reference: AVAudioRecorder reference

Then, you can use the following code:

// Init audio with record capability
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
    [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];

// Set recording setting
NSMutableDictionary* recordSetting = [[NSMutableDictionary alloc] init];
    [recordSetting setValue :[NSNumber numberWithInt:kAudioFormatMPEGLayer3] forKey:AVFormatIDKey];
    [recordSetting setValue:[NSNumber numberWithFloat:48000] forKey:AVSampleRateKey]; 
    [recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];
// Create a AVAudioRecorder object
tmpUrl = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent: [NSString stringWithFormat: @"tmp.mp3"]]];
AVAudioRecorder *recorder = [[AVAudioRecorder alloc] initWithURL:tmpUrl settings:recordSetting error:nil];

// Start the recorder
[recorder record];
// record your voice here
[recorder stop];

// Play recorded sound
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:tmpUrl error:nil];
[player play];

Here you are !!

olipion
hi thank you for information but i tried it its not working also i got another information i phone wont support mp3 coding. i have one more problem that iam not getting the voice which is reocrded simply iam getting zzzz... like sound
kumaryr
ill post my code
kumaryr