如何使用Swift 4在iOS中将音频格式从m4a转换为mp3?

问题描述 投票:-2回答:2

我正在从服务器下载.m4a格式的音频,只想将其转换为.mp3格式。

xcode mp3 audiokit m4a swift5.1
2个回答
0
投票

尝试此pod

如果需要安装CocoaPods的帮助,请单击此处:link


0
投票

您可以使用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安装的更多信息。

希望有帮助!

© www.soinside.com 2019 - 2024. All rights reserved.