Error while convering mp3 file to wav file format using python pydub module

Question:

I am trying to convert my mp3 file to wav format but its giving error like this

My Code

from pydub import AudioSegment

src = "my_result.mp3"
dst = "final.wav"

sound = AudioSegment.from_mp3(src)
sound.export("final.wav",format="wav")

But this code is returning this kind of error

C:Users91630AppDataLocalProgramsPythonPython311Libsite-packagespydubutils.py:170: RuntimeWarning: Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work
  warn("Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work", RuntimeWarning)     
C:Users91630AppDataLocalProgramsPythonPython311Libsite-packagespydubutils.py:198: RuntimeWarning: Couldn't find ffprobe or avprobe - defaulting to ffprobe, but may not work
  warn("Couldn't find ffprobe or avprobe - defaulting to ffprobe, but may not work", RuntimeWarning)  
Traceback (most recent call last):
  File "c:Users91630SearchesSciTech Dropboxmeruvu likithPCDesktoppython tempmp3_wav.py", line 6, in <module>
    sound = AudioSegment.from_mp3(src)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:Users91630AppDataLocalProgramsPythonPython311Libsite-packagespydubaudio_segment.py", line 796, in from_mp3
    return cls.from_file(file, 'mp3', parameters=parameters)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:Users91630AppDataLocalProgramsPythonPython311Libsite-packagespydubaudio_segment.py", line 728, in from_file
    info = mediainfo_json(orig_file, read_ahead_limit=read_ahead_limit)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:Users91630AppDataLocalProgramsPythonPython311Libsite-packagespydubutils.py", line 274, in mediainfo_json
    res = Popen(command, stdin=stdin_parameter, stdout=PIPE, stderr=PIPE)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:Users91630AppDataLocalProgramsPythonPython311Libsubprocess.py", line 1022, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:Users91630AppDataLocalProgramsPythonPython311Libsubprocess.py", line 1491, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [WinError 2] The system cannot find the file specified
Asked By: KARTX LEGEND YT

||

Answers:

If your ffmpeg is installed you need to add the path of ffmpeg to your environment variables’ PATH. I’ll explain for windows. First, find out where your ffmpeg is installed. Record that path, because you’ll need it. Use the windows search for environment variables to bring up that system menu (like this https://docs.oracle.com/en/database/oracle/machine-learning/oml4r/1.5.1/oread/creating-and-modifying-environment-variables-on-windows.html#GUID-DD6F9982-60D5-48F6-8270-A27EC53807D0). Once there, click on the variable called PATH. Then, add and paste in the path of your ffmpeg. This should allow pydub to access ffmpeg.

This is similar to this question: Pydub installation and ffmpeg which may be of further guidance in other systems.

Answered By: Shaun Ramsey
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.