2

所以有人写了一个笑话陷阱脚本(如“陷阱音乐”),我无法让它工作。

usage: trapifier.py [-h] [--samples [SAMPLES]] inputfile outputfile

然而,尽管文件夹看起来像这样

ls -l
total 14288
-rwxrwxrwx   1 ________  ________  7295612 Mar  2  2008 Chicago.mp3
-rwxr-xr-x@  1 ________  ________     1074 Apr 12 17:00 LICENSE
-rwxr-xr-x@  1 ________  ________     2871 Apr 12 17:00 README.md
-rwxr-xr-x@  1 ________  ________        6 Apr 12 17:00 requirements.txt
drwxr-xr-x@ 48 ________  ________     1632 Apr 12 17:00 samples
-rwxr-xr-x   1 ________  ________     2923 Apr 12 17:00 trapifier.py

此命令总是导致 [Errno 2] No such file or directory

./trapifier.py Chicago.mp3 Chiraq.mp3

或者

python trapifier.py Chicago.mp3 Chiraq.mp3

甚至

./trapifier.py /full/path/to/Chicago.mp3 Chiraq.mp3

是什么赋予了?我觉得某处有一个新手错误。

请求的完整错误消息:

    Traceback (most recent call last):
  File "./trapifier.py", line 89, in <module>
    overlay(parse())
  File "./trapifier.py", line 32, in parse
    base_track = pydub.AudioSegment.from_mp3(inputfile)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pydub/audio_segment.py", line 297, in from_mp3
    return cls.from_file(file, 'mp3')
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pydub/audio_segment.py", line 284, in from_file
    subprocess.call(convertion_command, stderr=open(os.devnull))
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 493, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 679, in     __init__
    errread, errwrite)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1249,     in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

脚本的来源托管在https://github.com/japesinator/trapifier.py

我拥有所有必需的库(argparse、pydub、os、random)。

第一个有用的编辑: pydub.AudioSegment 加载失败似乎是罪魁祸首。然而,事情变得陌生了。在 python 终端中,我可以做

from pydub import AudioSegment

但是当我这样做时,我得到一个没有这样的模块错误

导入 pydub.AudioSegment

4

1 回答 1

3

pydub 找不到用于解码和编码 mp3 文件(以及所有其他非波形格式)的 ffmpeg 是很常见的。如果您安装了 ffmpeg 但它仍然无法正常工作,您可以明确告诉 pydub 在哪里可以找到它,如下所示:

from pydub import AudioSegment
AudioSegment.ffmpeg = "/path/to/ffmpeg"

您可能还会发现我们的ffmpeg 设置文档很有帮助 =D

编辑 -不得已的选项:如果您尽了最大的努力仍然无法让 pydub 找到 ffmpeg,您可以在将文件传递给 pydub 之前将所有内容转换为波形格式。这肯定是最后的手段,但它会绕过 ffmpeg 问题,因为 pydub 原生支持 wave。

于 2014-04-14T20:16:54.013 回答