相关文章推荐
霸气的大葱  ·  C++中的inline函数_c++ ...·  5 月前    · 
愉快的奔马  ·  支持Windows CUDA、Mac ...·  1 年前    · 
怕老婆的猴子  ·  How to check your ...·  1 年前    · 
酷酷的日光灯  ·  jsp 分页 javabean jspdf ...·  2 年前    · 
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

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?

Can you share the actual code and the full error? Is file:///Path/to/file the actual argument you use in your code or is just you "censoring" the path? – Tomerikoo Sep 21, 2020 at 10:23 Here is the full Error I get: Traceback (most recent call last): File "/Volumes/Σ/[MARVEL]/JarvisVoice.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:///Volumes/Σ/[MARVEL]/sound.mp3 – illuminatro Sep 21, 2020 at 10:25

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.

@illuminatro Can you put here in comment new full path? The way that it has printed playsound in your Python exception? If not secret. I think you have spaces in folder/dirs names, they are not allowed. – Arty Sep 21, 2020 at 11:06 @illuminatro Did you also tried to upgrade library through python -m pip install --upgrade playsound? And checked dirs/file read permission for user running python? – Arty Sep 21, 2020 at 11:52 You may do cp sound.mp3 /tmp/ + sudo chmod 777 /tmp/sound.mp3 and then play /tmp/sound.mp3. – Arty Sep 21, 2020 at 11:53

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.