如何将.caf文件转换为.mp3文件?

时间:2015-12-17 08:25:05

标签: ios swift avfoundation audio-recording

我已使用以下方法将一些声音录入文档文件夹

 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()
    }
}

此方法会将audio.caf音频文件保存到文档目录中,但我想将此recording.caf文件转换为mp3以进行进一步操作。

如何在swift中将此.caf文件转换为.mp3?

1 个答案:

答案 0 :(得分:4)

由于版税问题,AVAudioRecorder不支持mp3编解码器 可用编解码器列表:

kAudioFormatMPEG4AAC
kAudioFormatAppleLossless
kAudioFormatAppleIMA4
kAudioFormatiLBC
kAudioFormatULaw
kAudioFormatLinearPCM

您可以在How do I record audio on iPhone with AVAudioRecorder?

找到详细信息