How to convert the .caf file to a .mp3 file?

I write some voice to the docs folder using the following methods

func record() { self.prepareToRecord() if let recorder = self.audioRecorder { recorder.record() } } let recordSettings = [ AVSampleRateKey : NSNumber(float: Float(44100.0)), AVFormatIDKey : NSNumber(int: Int32(kAudioFormatAppleLossless)), AVNumberOfChannelsKey : NSNumber(int: 2), AVEncoderAudioQualityKey : NSNumber(int: Int32(AVAudioQuality.Medium.rawValue)), AVEncoderBitRateKey : NSNumber(int: Int32(320000)) ] func prepareToRecord() { let documentsPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as NSString let soundFileURL: NSURL? = NSURL.fileURLWithPath("\(documentsPath)/recording.caf") print("\(soundFileURL)") self.audioRecorder = try! AVAudioRecorder(URL: soundFileURL!, settings: recordSettings) if let recorder = self.audioRecorder { recorder.prepareToRecord() } } 

This method will save the audio file as record.caf in the document directory, but I want to convert this record.caf file to mp3 for further manipulations.

How to convert this .caf file to .mp3 in swift?

+5
source share
2 answers

MP3 codec not supported by AVAudioRecorder due to royalty List of available codecs:

kAudioFormatMPEG4AAC
kAudioFormatAppleLossless
kAudioFormatAppleIMA4
kAudioFormatiLBC
kAudioFormatULaw
kAudioFormatLinearPCM

Here you can find the details. How to record audio on iPhone using AVAudioRecorder?

+4
source

For this you need to use Lame Encoder .

Here is a link that explains how to do this quickly.

wav for mp3 in fast

-1
source

Source: https://habr.com/ru/post/1238493/


All Articles