“OSError: [Errno 2] No such file or directory” converting mp3

自作多情 提交于 2021-02-11 14:40:35

问题


I'm trying to use Pydub, and I want to convert a mp3 file to wav, as is already told here.

Even though the file is present I'm getting a error of No such file or directory.

This is my code:

import os.path
print "File Present:", os.path.isfile('/home/nikhil/Documents/Python/IPython Notebooks/test.mp3') 

from pydub import AudioSegment
sound = AudioSegment.from_mp3('/home/nikhil/Documents/Python/IPython Notebooks/test.mp3')
sound.export("file.wav", format="wav")

And this is the complete log cat:

File Present: True

---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-29-d23db5440f1d> in <module>()
      9 
     10 from pydub import AudioSegment
---> 11 sound = AudioSegment.from_mp3('/home/nikhil/Documents/Python/IPython Notebooks/test.mp3')
     12 sound.export("file.wav", format="wav")
     13 

/usr/local/lib/python2.7/dist-packages/pydub/audio_segment.pyc in from_mp3(cls, file, parameters)
    700     @classmethod
    701     def from_mp3(cls, file, parameters=None):
--> 702         return cls.from_file(file, 'mp3', parameters)
    703 
    704     @classmethod

/usr/local/lib/python2.7/dist-packages/pydub/audio_segment.pyc in from_file(cls, file, format, codec, parameters, **kwargs)
    656             stdin_data = file.read()
    657 
--> 658         info = mediainfo_json(orig_file)
    659         if info:
    660             audio_streams = [x for x in info['streams']

/usr/local/lib/python2.7/dist-packages/pydub/utils.pyc in mediainfo_json(filepath)
    242 
    243     command = [prober, '-of', 'json'] + command_args
--> 244     res = Popen(command, stdin=stdin_parameter, stdout=PIPE, stderr=PIPE)
    245     output, stderr = res.communicate(input=stdin_data)
    246     output = output.decode("utf-8", 'ignore')

/usr/lib/python2.7/subprocess.pyc in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags)
    709                                 p2cread, p2cwrite,
    710                                 c2pread, c2pwrite,
--> 711                                 errread, errwrite)
    712         except Exception:
    713             # Preserve original exception in case os.close raises.

/usr/lib/python2.7/subprocess.pyc in _execute_child(self, args, executable, preexec_fn, close_fds, cwd, env, universal_newlines, startupinfo, creationflags, shell, to_close, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite)
   1341                         raise
   1342                 child_exception = pickle.loads(data)
-> 1343                 raise child_exception
   1344 
   1345 

OSError: [Errno 2] No such file or directory

(Please ignore the format of error. I prefer it this way(indented))

What is going wrong here?


回答1:


EDIT

I just saw people with the same problem, and it was because they didn't had installed the ffmpeg library. Try:

sudo apt-get install ffmpeg

or

sudo apt-get install libav-tools



回答2:


Your path is used as argument in Popen function as your traceback shows.

Try adding additional quotes:

sound = AudioSegment.from_mp3('"/home/nikhil/Documents/Python/IPython Notebooks/test.mp3"')


来源:https://stackoverflow.com/questions/50798198/oserror-errno-2-no-such-file-or-directory-converting-mp3

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!