0

I am trying to upload an MP3 file and play it using pydub:

import pydub
from pydub import AudioSegment
from pydub.playback import play

blast_file = AudioSegment.from_mp3(
                                   "C:/Users/am650/Downloads/radio_static.mp3")

From this, I get the following error:

C:\Users\am650\PycharmProjects\pythonProject\venv\Scripts\python.exe C:\Users\am650\PycharmProjects\pythonProject\crtt_control.py 
C:\Users\am650\PycharmProjects\pythonProject\venv\Lib\site-packages\pydub\utils.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:\Users\am650\PycharmProjects\pythonProject\venv\Lib\site-packages\pydub\utils.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:\Users\am650\PycharmProjects\pythonProject\crtt_control.py", line 38, in <module>
    blast_file = AudioSegment.from_mp3(
                 ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\am650\PycharmProjects\pythonProject\venv\Lib\site-packages\pydub\audio_segment.py", line 796, in from_mp3
    return cls.from_file(file, 'mp3', parameters=parameters)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\am650\PycharmProjects\pythonProject\venv\Lib\site-packages\pydub\audio_segment.py", line 728, in from_file
    info = mediainfo_json(orig_file, read_ahead_limit=read_ahead_limit)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\am650\PycharmProjects\pythonProject\venv\Lib\site-packages\pydub\utils.py", line 274, in mediainfo_json
    res = Popen(command, stdin=stdin_parameter, stdout=PIPE, stderr=PIPE)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\am650\AppData\Local\Programs\Python\Python311\Lib\subprocess.py", line 1024, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\am650\AppData\Local\Programs\Python\Python311\Lib\subprocess.py", line 1493, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [WinError 2] The system cannot find the file specified

Process finished with exit code 1

I have messed around with forward and back slashes, I tried putting r in front of the file call (r"C:/Users/am650/Downloads/radio_static.mp3"), I have moved the file to different locations, etc. I have also tried other files and file types. It seems that python cannot find any file of mine...

I originally wrote this code on a mac (where it worked fine) and moved it to a PC. This error is occurring on the PC (windows 10). I am using Python 3.11.1 and I only have one version of Python downloaded. I had a similar problem earlier where Python would not recognise any of my pip installs, but I got around this by adding the packages directly in pycharm using PyPl. I now wounder if these two issues are related?

It is also worth noting that I am using a school computer that was configured such that all downloads automatically save to one drive, not the local computer. I have moved python (and the audio file) to the computer drive but maybe I have missed a file somewhere? I do not have another PC on which I can test these theories, and my IT department took a look and could not figure it out.

  • Welcome to Stack Overflow. It looks like this code works by trying to launch another program on your computer to play the audio file. Most likely, the problem is with the path **to that executable**. Do you expect that to happen - for example, because of **reading the documentation** to understand how the library works? If you are expecting it to run some application, then can you figure out what the path is? Since this is Windows, check if there are any spaces in that path, and if you can relocate to a different path without spaces and make the library use that. – Karl Knechtel Jan 13 '23 at 11:08
  • In the stack trace we see *blast_file = AudioSegment.from_mp3* whereas in the code fragment you're showing it's *sound_file = AudioSegment.from_mp3* – DarkKnight Jan 13 '23 at 11:09
  • At any rate, if you cannot get a "hello world" example of someone else's library code to work, then that is a tech support question for the authors; please try e.g. the project's issue tracker instead. – Karl Knechtel Jan 13 '23 at 11:09
  • 1
    It looks like this is [a known problem with the library that many people are complaining about, with no response from the developer](https://github.com/jiaaro/pydub/issues/306). – Karl Knechtel Jan 13 '23 at 11:13
  • As such, the error message seems to be about whatever was passed to `Popen` in `command`, rather than the audio file you thought was the problem. The linked bug reports mentions (having `ffmpeg` installed, and then) adding the directory which contains the `ffmpeg.exe` binary (without the `.exe` if you are not on Windows) to your `PATH` as a workaround. – tripleee Jan 13 '23 at 11:24
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Jan 13 '23 at 12:06

1 Answers1

0

If you look closely to the error trace you will find that the problem is not in your file but in the program. According the source it looks for the exe in the local folder or in the system PATH folders. Probably you forgot to copy ffmpeg.exe into your program folder.

viilpe
  • 767
  • 1
  • 5
  • 10
  • Hey there! Thanks for the help. I got the ffmpeg thing sorted out (I tried several methods with no luck, until I manually dragged the files into my python project folder. Now I am getting a permission error that I can't figure out how to handle. I will update my question to include that :) – grace.cutler Jan 13 '23 at 12:57