我发现我在这里遇到了一道难题,仅仅尝试将音频文件加载到pydub进行转换时,它就一直抛出一个"[Errno 2] No such file or directory"的错误。
自然而然地,我花了太多的时间确保路径有效,尝试了相对路径和绝对路径,并确认python方法open()使用完全相同的路径是可以正常工作的。
我正在通过anaconda 2.3 distrib在ubuntu上使用ipython 3.2和python 2.7。
自然而然地,我花了太多的时间确保路径有效,尝试了相对路径和绝对路径,并确认python方法open()使用完全相同的路径是可以正常工作的。
我正在通过anaconda 2.3 distrib在ubuntu上使用ipython 3.2和python 2.7。
from pydub import AudioSegment
sound = AudioSegment.from_mp3("/absolute/path/to/file.mp3")
尝试在路径中去除空格,因为空格有时会导致问题。以下是完整的错误日志:
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
<ipython-input-15-8b1ec013ca8e> in <module>()
1 import pydub
----> 2 sound = pydub.AudioSegment.from_mp3("/absolute/path/to/file.mp3")
/home/ludo/anaconda3/envs/python2/lib/python2.7/site-packages/pydub/audio_segment.pyc in from_mp3(cls, file)
421 @classmethod
422 def from_mp3(cls, file):
--> 423 return cls.from_file(file, 'mp3')
424
425 @classmethod
/home/ludo/anaconda3/envs/python2/lib/python2.7/site-packages/pydub/audio_segment.pyc in from_file(cls, file, format, **kwargs)
404 log_conversion(conversion_command)
405
--> 406 p = subprocess.Popen(conversion_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
407 p_out, p_err = p.communicate()
408
/home/ludo/anaconda3/envs/python2/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)
708 p2cread, p2cwrite,
709 c2pread, c2pwrite,
--> 710 errread, errwrite)
711 except Exception:
712 # Preserve original exception in case os.close raises.
/home/ludo/anaconda3/envs/python2/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)
1333 raise
1334 child_exception = pickle.loads(data)
-> 1335 raise child_exception
1336
1337
OSError: [Errno 2] No such file or directory
我是否忽略了什么非常简单的东西或者是...?
编辑: 我还尝试将路径作为原始文本r"/absolute/path/to/file.mp3"传递,就像Vaulstein所问的那样-但是我得到了相同的错误。
r"/absolute/path/to/file.mp3"
,以防它包含特殊字符。 - Vaulsteinimport pydub sound = pydub.AudioSegment.from_mp3("/absolute/path/to/file.mp3")
- Vaulstein