I have record some voice in to the Document Folder using 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 recording.caf in to the Document Directory, but I want to convert this recording.caf file in to mp3 for further manipulation.
How to convert this .caf file to .mp3 in swift ?
mp3 codec is not supported by AVAudioRecorder because of royalty The list of available codecs:
kAudioFormatMPEG4AAC
kAudioFormatAppleLossless
kAudioFormatAppleIMA4
kAudioFormatiLBC
kAudioFormatULaw
kAudioFormatLinearPCM
You can find the details here How do I record audio on iPhone with AVAudioRecorder?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With