0

I Saw this question here. But my file is already in wav. My code is a timer which plays sound after timer ends using threading. It wasn't working there, then I tried it in different file which just had the file and library:

from playsound import playsound

playsound('alarm.wav')

When I do this following error occurs:

Error 259 for command:
        play alarm.wav wait
    The driver cannot recognize the specified command parameter.
Traceback (most recent call last)
...
playsound.PlaysoundException: 
    Error 259 for command:
        play alarm.wav wait
    The driver cannot recognize the specified command parameter.

But when I give the path:

from playsound import playsound

playsound('path/to/alarm.wav')

the following error occurs in a pop box (SyntaxError):

(unicode error)some stuff after that

I'm on Windows and I tried it on IDLE and by double clicking the file (Python3.7.3).

If it helps, it works on a different device (both have same Python versions).

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
Pratyush Arora
  • 137
  • 1
  • 11
  • do you use Windows on other device? As I know `playsound` use system program `play` to run it and it may need to install it manually - it is not Python module but normal .exe file - on my Linux `play` runs [SoX](http://sox.sourceforge.net/). Other problem can be `/` in path - on Linux it may work but Windows may need `\ ` or `\\ ` – furas Sep 19 '21 at 20:48
  • Yeah, I use windows on both devices. I installed it via pip command and its installed in the correct location.I `\\` used this but said unicode codec error – Pratyush Arora Sep 20 '21 at 10:43
  • 1
    you have to use \\ because single \ has special meaning in strings - even in path - like `\n` for new line, `\t` for tab, `\u...` for unicode, etc. OR you have to use prefix `r` for `raw` string - `r"C:\full\path\to\file.wav"` – furas Sep 20 '21 at 12:25
  • What is the playsound version? I got the same error too. I tried downgrading playsound version to 1.2.2. Then it worked for me. – Nishani Kasineshan Oct 05 '21 at 06:10

2 Answers2

7

Run this in CMD or any such terminal:

pip install playsound==1.2.2

Downgrading the version works perfectly for me :)

Itchydon
  • 2,572
  • 6
  • 19
  • 33
Habib Mollah
  • 71
  • 1
  • 1
3

I try to use code:

playsound(u"path/to/alarm.wav")

and it works well for me (python 3.9.5, playsound 1.3.0, windows 11 platform)