我正在从服务器下载 .m4a 格式的音频,只想将其转换为 .mp3 格式。
您可以使用 AudioKit(一个 iOS/MacO 开源音频库)来完成此操作。
这是如何使用 AudioKit 将 m4a 转换为 mp4(据我所知似乎不支持 mp3):
//first load the file to convert
let audiofile : AKAudioFile
do{
audiofile = try AKAudioFile(readFileName: "Samples/audio1.caf")
} catch let error as NSError {
print(error.description)
return
}
//declare the callback, it will be called during conversion
func callback(processedFile: AKAudioFile?, error: NSError?) {
AKLog("Export completed!")
// Check if processed file is valid (different from nil)
if let converted = processedFile {
AKLog("Export succeeded, converted file: \(converted.fileNamePlusExtension)")
} else {
// An error occurred. So, print the Error
AKLog("Error: \(error?.localizedDescription)")
}
}
//start the conversion
audiofile.exportAsynchronously(name: "convertedfile", baseDir: .documents, exportFormat: .mp4, callback: callback)
当然,您需要在 Xcode 项目中安装 AudioKit(非常简单,只需拖放 AudioKit 框架即可,您可以在此处下载:AudioKit 发布页面)。检查此链接以获取有关 AudioKit 安装的更多信息。