jiaaro / pydub

Manipulate audio with a simple and easy high level interface
http://pydub.com
MIT License
8.59k stars 1.01k forks source link

Problems with AudioSegment.from_mp3() #633

Open ywbird opened 2 years ago

ywbird commented 2 years ago

Hi! When I'm trying to open mp3 with:

letter_sound = AudioSegment.from_mp3(os.path.join('samples', '%s.mp3' % letter))

(I double checked folder and .mp3 file were exist) I'm getting:

---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_12328/1073574614.py in <module>
     10             tts.save('samples/%s.mp3' % letter)
     11 
---> 12         letter_sound = AudioSegment.from_mp3(os.path.join('samples', '%s.mp3' % letter))
     13 
     14         raw = letter_sound.raw_data[5000:-5000]

~\AppData\Local\Programs\Python\Python310\lib\site-packages\pydub\audio_segment.py in from_mp3(cls, file, parameters)
    794     @classmethod
    795     def from_mp3(cls, file, parameters=None):
--> 796         return cls.from_file(file, 'mp3', parameters=parameters)
    797 
    798     @classmethod

~\AppData\Local\Programs\Python\Python310\lib\site-packages\pydub\audio_segment.py in from_file(cls, file, format, codec, parameters, start_second, duration, **kwargs)
    726             info = None
    727         else:
--> 728             info = mediainfo_json(orig_file, read_ahead_limit=read_ahead_limit)
    729         if info:
    730             audio_streams = [x for x in info['streams']

~\AppData\Local\Programs\Python\Python310\lib\site-packages\pydub\utils.py in mediainfo_json(filepath, read_ahead_limit)
    272 
    273     command = [prober, '-of', 'json'] + command_args
--> 274     res = Popen(command, stdin=stdin_parameter, stdout=PIPE, stderr=PIPE)
    275     output, stderr = res.communicate(input=stdin_data)
    276     output = output.decode("utf-8", 'ignore')

~\AppData\Local\Programs\Python\Python310\lib\subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, user, group, extra_groups, encoding, errors, text, umask, pipesize)
    964                             encoding=encoding, errors=errors)
    965 
--> 966             self._execute_child(args, executable, preexec_fn, close_fds,
    967                                 pass_fds, cwd, env,
    968                                 startupinfo, creationflags, shell,

~\AppData\Local\Programs\Python\Python310\lib\subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_gid, unused_gids, unused_uid, unused_umask, unused_start_new_session)
   1433             # Start the process
   1434             try:
-> 1435                 hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
   1436                                          # no special security
   1437                                          None, None,

FileNotFoundError: [WinError 2] The system cannot find the file specified

(I'm running this on Jupyter notebook on VSCode)

How can I fix it? I think it's problem with C:\Users\username\AppData\Local\Programs\Python\Python310\Lib\subprocess.py's winapi create process function. But I can't find the problem.


syockit commented 2 years ago

The FileNotFoundError actually refers to ffmpeg binary. Make sure ffmpeg.exe is visible from your PATH.