我正在从服务器下载.m4a格式的音频,只想将其转换为.mp3格式。
您可以使用AudioKit(iOS / MacOs开源音频库)执行此操作>
这里是您如何通过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 Releases page即可下载)。检查link以获取有关AudioKit安装的更多信息。
希望有帮助!