[英]Why I can't use “play()” function in PyDub?
I just wrote simple code to play some music, using PyDub module in Python:我只是编写了简单的代码来播放一些音乐,使用 Python 中的 PyDub 模块:
from pydub import AudioSegment
from pydub.playback import play
audio1 = AudioSegment.from_wav("music.wav")
play(audio1)
But I get this error:但我收到此错误:
Traceback (most recent call last):
File "D:\codes\Lessons.IzuchaemPython\pydub1.py", line 16, in <module> play(audio1)
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\pydub\playback.py", line 71, in play _play_with_ffplay(audio_segment)
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\pydub\playback.py", line 15, in _play_with_ffplay
seg.export(f.name, "wav")
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\pydub\audio_segment.py", line 867, in export
out_f, _ = _fd_or_path_or_tempfile(out_f, 'wb+')
File "C:\Users\User\AppData\Local\Programs\Python\Python39\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\\User\\AppData\\Local\\Temp\\tmp4_bp0wu1.wav'
I have installed FFmpeg.我已经安装了 FFmpeg。 Please, explain to me how to make this simple program work.请向我解释如何使这个简单的程序工作。
You need to have either pyaudio
installed or ffplay
.你需要有任何pyaudio
安装或ffplay
。
It will obviously open another window since it needs an application to play the audio, as an FYI.它显然会打开另一个窗口,因为它需要一个应用程序来播放音频,仅供参考。 (Can't play from command prompt or terminal ;P) (无法从命令提示符或终端播放;P)
Otherwise it should work, function is working fine for me.否则它应该可以工作,功能对我来说工作正常。
Note: Also make sure you are in the right directories etc.,注意:还要确保您位于正确的目录等中,
You can look this Errno 13 Permission denied Python你可以看看这个Errno 13 Permission denied Python
or或者
I see the web from https://realpython.com/playing-and-recording-sound-python/我从https://realpython.com/playing-and-recording-sound-python/看到网络
Although pydub can open and save WAV files without any dependencies, you need to have an audio playback package installed to play audio.虽然pydub可以在没有任何依赖的情况下打开和保存WAV文件,但是你需要安装一个音频播放包来播放音频。
Myabe you should try to install an audio playback. Myabe 你应该尝试安装一个音频播放器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.