0

我正在尝试将 pydub 用于音乐项目,但是在尝试使用这段代码播放声音时

from pydub import AudioSegment
from pydub.playback import play
sound = AudioSegment.from_wav("s1.wav")
play(sound)

我收到以下错误:

RuntimeWarning: Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work
  warn("Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work", RuntimeWarning)
C:\Python\Python385\lib\site-packages\pydub\utils.py:184: RuntimeWarning: Couldn't find ffplay or avplay - defaulting to ffplay, but may not work
  warn("Couldn't find ffplay or avplay - defaulting to ffplay, but may not work", RuntimeWarning)
Traceback (most recent call last):
  File "C:/Users/vicen/Desktop/music project/mian.py", line 6, in <module>
    play(s1)
  File "C:\Python\Python385\lib\site-packages\pydub\playback.py", line 74, in play
    _play_with_ffplay(audio_segment)
  File "C:\Python\Python385\lib\site-packages\pydub\playback.py", line 18, in _play_with_ffplay
    seg.export(f.name, "wav")
  File "C:\Python\Python385\lib\site-packages\pydub\audio_segment.py", line 809, in export
    out_f, _ = _fd_or_path_or_tempfile(out_f, 'wb+')
  File "C:\Python\Python385\lib\site-packages\pydub\utils.py", line 60, in _fd_or_path_or_tempfile
    fd = open(fd, mode=mode)
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\vicen\\AppData\\Local\\Temp\\tmpvwotqts5.wav'

有人明白为什么它不起作用吗?我对python相当陌生,所以我不知道。

4

2 回答 2

0

从这里轻松修复:

pip install simpleaudio

Pydub广泛使用临时文件。正如这里建议的那样,您可以添加TMPDIR环境变量。

于 2021-02-27T13:47:19.730 回答
0

python脚本遇到了Permission Error 它正在尝试读取'C:\\Users\\vicen\\AppData\\Local\\Temp\\tmpvwotqts5.wav' 文件但没有在目录中写入的权限。

更改上述临时文件夹的权限应该可以解决问题。

sudo或者您可以使用命令运行您的 python 脚本。由于您使用的是 Windows ,在这方面应该有所帮助。

于 2021-02-27T12:58:36.937 回答