I tried to use the playsound module to play an audio file. When I run my code I get this error:
Traceback (most recent call last):
File "/Users/Tarantino/Desktop/CodeTesting/sound.py", line 3, in <module>
playsound('sound.mp3')
File "/Users/Tarantino/Library/Python/3.8/lib/python/site-packages/playsound.py", line 67, in _playsoundOSX
raise IOError('Unable to load sound named: ' + sound)
OSError: Unable to load sound named: file:///Users/Tarantino/Desktop/Code Testing/sound.mp3
I have the audio file in the same folder as the Python code, could I please get help on what to do?
Move file you're playing to folder that has no special or non-ascii characters on the full path from root of disk, spaces in files/dirs names are not allowed too. Because
playsound
is creating an URL from full path-location of file and this URL should has valid for URLs chars.E.g.
/x/y/z.mp3
path is alright, but/x y/z.mp3
and/x[y]/z.mp3
and/x/漢/z.mp3
are not.Also try upgrading library via
python -m pip install --upgrade playsound
, I've just installed library and tried playing sound and it plays for me.Also some dir on the path might not have read permissions for the user you are running python with.