I am developing an iPhone app which records the audio in .wav format.
Here is the code:
NSMutableDictionary* recordSetting = [[NSMutableDictionary alloc]init];
[recordSetting setValue :[NSNumber numberWithInt:kAudioFormatLinearPCM] forKey:AVFormatIDKey];
[recordSetting setValue:[NSNumber numberWithFloat:11025.0] forKey:AVSampleRateKey];
[recordSetting setValue:[NSNumber numberWithInt: 1] forKey:AVNumberOfChannelsKey];
[recordSetting setValue:[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentsDirectory = [path objectAtIndex:0];
NSString *myDBnew = [documentsDirectory stringByAppendingPathComponent:@"test.wav"];
recordedTmpFile = [NSURL fileURLWithPath:myDBnew];
NSLog(@"Using File called: %@",recordedTmpFile);
recorder = [[ AVAudioRecorder alloc] initWithURL:recordedTmpFile settings:recordSetting error:&error];
[recorder setDelegate:self];
[recorder prepareToRecord];
[recorder record];
Above code is recording audio in .wav format. If I want to record audio in MP3 using key kAudioFormatMPEGLayer3(mp3)
instead of kAudioFormatLinearPCM(.wav)
, what other changes do I need to make? Changes in recordSetting dictionary like sample rate, channel and all.
Or suggest any audio format which is compatible with both iPhone and Android, smaller in size and can be recorded directly from iPhone app.