前段时间我做了一个小项目,最近我觉得给它添加一些声音会很酷。所以我寻找在 Python 3.x 中播放声音的方法,并Playsound
得到了很好的评价。我有这样的设置:我有文件夹Python Projects
,里面有Sound Test
但是当我尝试播放我的音频文件(test.wav
)时,它会抛出以下错误:
Traceback (most recent call last):
File "soundtest.py", line 2, in <module>
playsound('test.wav')
File "/Users/rhett/env/lib/python3.7/site-packages/playsound.py", line 67, in _playsoundOSX
raise IOError('Unable to load sound named: ' + sound)
OSError: Unable to load sound named: file:///Users/rhett/Desktop/Python Projects/Sound Test/test.wav
我尝试使用直接路径,例如:
from playsound import playsound
playsound(/Users/Rhett/Desktop/Python\ Projects/Sound\ Test/test.wav)
我收到了完全相同的错误:
Traceback (most recent call last):
File "Sound Test/soundtest.py", line 2, in <module>
playsound("/Users/Rhett/Desktop/Python\ Projects/Sound\ Test/test.wav")
File "/Users/rhett/env/lib/python3.7/site-packages/playsound.py", line 67, in _playsoundOSX
raise IOError('Unable to load sound named: ' + sound)
OSError: Unable to load sound named: file:///Users/Rhett/Desktop/Python\ Projects/Sound\ Test/test.wav