How to record an audio file in .mp3 format?

做~自己de王妃 提交于 2019-11-27 02:50:49

问题


I am using the following settings for recording 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 not able to record with these. I searched a lot for this but wasn't able to get some relevant post. Some posts say that it is not possible.If its not possible then why so? Please answer.


回答1:


The Problem is kAudioFormatMPEGLayer3 which 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 in to MP3 Format.

The other supported encoding for Recording purpose are

kAudioFormatMPEG4AAC   
kAudioFormatAppleLossless  
kAudioFormatAppleIMA4   
kAudioFormatiLBC 
kAudioFormatULaw 
kAudioFormatLinearPCM 

For more info you can refer to this post of SO.



来源:https://stackoverflow.com/questions/4871940/how-to-record-an-audio-file-in-mp3-format

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!