我正在尝试运行简单的代码,以用playsound播放wav声音,(我在某些网站上发现了这种声音播放方式):
from playsound import playsound
playsound("Piano.wav")
,当我运行它时,出现错误:
Traceback (most recent call last):
File "C:/Users/user/AppData/Local/Programs/Python/Python38/ьгышсф.py", line 3, in <module>
playsound("Piano.wav")
File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\site-packages\playsound.py", line 35, in _playsoundWin
winCommand('open "' + sound + '" alias', alias)
File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\site-packages\playsound.py", line 30, in winCommand
'\n ' + errorBuffer.value.decode())
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc4 in position 0: invalid continuation byte
与mp3文件相同。我正在使用Python 3.8
答案 0 :(得分:1)
您得到的错误(275
= MCIERR_FILE_NOT_FOUND
)是系统找不到声音文件。您需要指定文件的完整路径,而不仅仅是文件名:
playsound("C:\\Path\\To\\Piano.wav")
如果声音文件位于脚本文件所在的目录或子目录中,请参见How to properly determine current script directory?,以了解如何在运行时获取脚本文件的路径。
答案 1 :(得分:0)
当您的路径中包含非 UTF-8 字符(如 Ü、Ö...)时,您通常会收到此错误。尽量避免在您的声音文件路径中包含此类字符。