"OSError: [Errno 2] Нет такого файла или каталога" конвертирование mp3 - PullRequest
0 голосов
/ 11 июня 2018

Я пытаюсь использовать Pydub , и я хочу преобразовать файл mp3 в wav, как уже сказано здесь .

Несмотря на наличие файла, я получаю сообщение об ошибке No such file or directory.

Это мой код:

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")

И это полный журнал 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

( Пожалуйста, игнорируйте формат ошибки. Я предпочитаю этот способ (с отступом) )

Что здесь не так?

Ответы [ 2 ]

0 голосов
/ 11 июня 2018

Ваш путь используется в качестве аргумента в функции Popen, как показывает ваша трассировка.

Попробуйте добавить дополнительные кавычки:

sound = AudioSegment.from_mp3('"/home/nikhil/Documents/Python/IPython Notebooks/test.mp3"')
0 голосов
/ 11 июня 2018

РЕДАКТИРОВАТЬ

Я просто видел людей с такой же проблемой, потому что они не установили библиотеку ffmpeg.Попробуйте:

sudo apt-get install ffmpeg

или

sudo apt-get install libav-tools
...