Search code examples
pythonpython-3.xffmpeg

converting mp3 to wav using ffmpeg and pydub


I am trying to convert mp3 file into wav using below code:

from os import path
from pydub import AudioSegment

# assign files
input_file = "recording.mp3"
output_file = "result.wav"

# convert mp3 file to wav file
sound = AudioSegment.from_mp3(input_file)
sound.export(output_file, format="wav")

This is the error: enter image description here


Solution

  • Try this:

    import subprocess
    
    # convert wav to mp3
    subprocess.call(['ffmpeg', '-i', source_path,
                         destination_path])