playsound package to play sound in python

61 views Asked by At

the code:

from playsound import playsound
playsound("C:\Users\Code Red\Desktop\alarm clock\anotherlove.mp3")

output:

File "c:\Users\Code Red\Desktop\alarm clock\alarm-clock-using-python.py", line 3
    playsound("C:\Users\Code Red\Desktop\alarm clock\anotherlove.mp3")

SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
1

There are 1 answers

0
The-Lomax On

It might be an issue with your file path. Rather than using an absolute path, try to put the sound file in the directory of your code and run with:

playsound("anotherlove.mp3")

Worked for me on mac. It might have issues with spaces within folder names. Try avoiding that.