我已经使用以下方法在Document文件夹中录制了一些声音
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()
}
}
此方法将音频文件作为recording.caf保存到文档目录中,但我希望将此recording.caf文件转换为mp3以便进一步操作。
如何在swift中将此.caf文件转换为.mp3?
发布于 2015-12-17 08:43:16
由于可用编解码器列表中的版税,AVAudioRecorder不支持mp3编解码器:
kAudioFormatMPEG4AAC
kAudioFormatAppleLossless
kAudioFormatAppleIMA4
kAudioFormatiLBC
kAudioFormatULaw
kAudioFormatLinearPCM
您可以在此处找到详细信息How do I record audio on iPhone with AVAudioRecorder?
发布于 2015-12-21 10:12:04
https://stackoverflow.com/questions/34329816
复制