运行代码片段时,出现标题中的错误。
我已经重新安装了软件包pydub
,以及pip3 install ffprobe
。
from pydub.playback import play
from pydub import AudioSegment
def change_volume(file_name, alteration):
song = AudioSegment.from_mp3(file_name)
new_song = song + alteration
new_title = ("_%s") % (file_name)
new_song.export(new_title, format='mp3')
change_volume("test_sample.mp3", 3)
代码的输出应该是目录中的一个新的 mp3 文件,音量水平略有提高 (test.mp3
--> _test.mp3
),而不是我得到错误:
FileNotFoundError: [Errno 2] No such file or directory: 'ffprobe': 'ffprobe'
最佳答案
首先确保你安装了ffprobe,它是FFmpeg的一部分,所以实际上你需要安装ffmpeg。您可以按照这两个站点之一的说明进行操作。
https://ffmpeg.org/download.html
https://github.com/adaptlearning/adapt_authoring/wiki/Installing-FFmpeg
之后,您需要将库添加到您的系统路径中,以便 python 能够找到并使用它。这可以通过将 FFmpeg 的安装路径实际添加到您的操作系统路径(如何操作取决于您的操作系统),或通过将其添加到 python 内部使用的临时路径变量来完成。
import sys
sys.path.append('/path/to/ffmpeg')
对于第二个选项,您必须确保在导入任何其他内容之前将路径附加到 FFmpeg。如果您没有更改根系统配置的选项,这是更好的选择,但当被不同的 python 脚本使用时会变得非常不一致。
最后确保安装了 ffprobe
(例如,在终端中使用 pip install ffprobe
,参见 https://pypi.org/project/ffprobe)以便 import ffprobe
应该在 python 环境中工作。
关于python - 找不到文件错误 : [Errno 2] No such file or directory: 'ffprobe' : 'ffprobe' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57350259/