Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
534 views
in Technique[技术] by (71.8m points)

iphone - How to record an audio file in .mp3 format?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...