Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
A while ago I made a little project, and I recently thought it would be cool to add some sounds to it as well. So I looked for ways to play sound in Python 3.x, and
Playsound
was well reviewed. I have it setup like so: I have folder
Python Projects
and inside that I have
Sound Test
But when I try to play my audio file (
test.wav
) it throws the following error:
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
I tried using the direct path, e.g.:
from playsound import playsound
playsound(/Users/Rhett/Desktop/Python\ Projects/Sound\ Test/test.wav)
I received the exact same error:
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
–
–
–
–
I have found where the problem is.
In the python3.7/site-packages/playsound.py
file
The developer has not checked for " " spaces in file path, so spaces character in the file path is creating trouble.
A quick fix without changing playsound.py
's code.
replace your folder name
~/Desktop/Python Projects/Sound Test/test.wav
with ~/Desktop/PythonProjects/SoundTest/test.wav
(i.e, remove spaces from folder names)
This will fix your error.
s_musicfile = "/Users/xxxxxxxxxx/Desktop/play this file.mp3"
s_musicfile = s_musicfile.replace(" ", "%20")
playsound(s_musicfile)
I think this will work try it especially when it is for raspberry :
Python 2:
sudo apt install python-gst-1.0
Python 3:
sudo apt install python3-gst-1.0
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.