-1

I am downloading audio from server in .m4a format and just want to convert it in .mp3 format.

ALOK RANJAN
  • 9
  • 1
  • 2
  • `I am downloading audio from server in .m4a format and just want to convert it in .mp3 format.` - that's good but what have you tried to solve this issue? – nopassport1 Jan 24 '20 at 10:09

1 Answers1

0

You can do this with AudioKit, an iOS/MacOs open-source audio lib

Here is how you can convert m4a to mp4 with AudioKit (mp3 does not seems to be supported as far as I know):

    //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)

Of course, you will need to have AudioKit installed in your Xcode project (very simple, just drag'n'drop the AudioKit frameworks that you can download here: AudioKit Releases page). Chech this link for more info about AudioKit install.

Hope it helps!

Relpot
  • 104
  • 3