0

I'm trying to play a .mp3 file.

My code :

import os

os.system("start C:\Users\User\Desktop\Wakeup.mp3")

But, it gives an error like this:

File "C:/Users/User/PycharmProjects/pythonProject/Test.py", line 2
    os.system("start C:\Users\User\Desktop\Wakeup.mp3")
             ^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 8-9: truncated \UXXXXXXXX escape

with other variants for playing a sound, I'm getting the same error

Thanks for attention

SSK
  • 3,444
  • 6
  • 32
  • 59

2 Answers2

2

You did not escape the backslash character. try this:

os.system("start C:\\Users\\User\\Desktop\\Wakeup.mp3")

Option 2

Use forward slash instead:

os.system("start C:/Users/User/Desktop/Wakeup.mp3")

Option 3

Use "raw" string:

os.system(r"start C:\Users\User\Desktop\Wakeup.mp3")
kdcode
  • 524
  • 2
  • 7
0

If you want to play sound. You can do something like this.

from playsound import playsound

playsound("path/name.mp3")

Hope this helps ... :D

Karan Owalekar
  • 947
  • 10
  • 31