How to record an audio file in .mp3 format?

I use the following settings to record an audio file in .mp3 format using AVAudioRecorder.

NSDictionary *recordSettings = [[NSDictionary alloc] initWithObjectsAndKeys: [NSNumber numberWithFloat: 44100.0],AVSampleRateKey, [NSNumber numberWithInt: kAudioFormatMPEGLayer3],AVFormatIDKey, [NSNumber numberWithInt: 1], AVNumberOfChannelsKey, [NSNumber numberWithInt: AVAudioQualityMax],AVEncoderAudioQualityKey,nil]; 

But failed to record with them. I searched a lot for this, but could not get the corresponding position. Some reports say this is not possible. If this is not possible, then why? Please reply.

+7
source share
1 answer

kAudioFormatMPEGLayer3 problem that is not supported by AVAudioRecorder .

Alternatively, you can use kAudioFormatAppleIMA4 for your recording purpose.

Finally, you can write your own encoding logic to convert kAudioFormatAppleIMA4 to MP3 Format.

Another supported encoding for the purpose of recording is

 kAudioFormatMPEG4AAC kAudioFormatAppleLossless kAudioFormatAppleIMA4 kAudioFormatiLBC kAudioFormatULaw kAudioFormatLinearPCM 

For more information, you can refer to this SO post.

+12
source

All Articles