我已使用以下方法将一些声音录入文档文件夹
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?
答案 0 :(得分:4)
kAudioFormatMPEG4AAC
kAudioFormatAppleLossless
kAudioFormatAppleIMA4
kAudioFormatiLBC
kAudioFormatULaw
kAudioFormatLinearPCM