What is the error in the code for this playsound module even though the syntax is same as on official site?
Asked Answered
F

4

1

I have checked path variables too everything works fine for other functions but it is showing error for this module only. Code:

from playsound import playsound
playsound('E://PYTHON//Music.mp3')

The following is the error:

PS C:\Users\HP> & C:/Users/HP/AppData/Local/Programs/Python/Python39/python.exe e:/PYTHON/Playsound.py

    Error 263 for command:
        open E://PYTHON//Music.mp3
    The specified device is not open or is not recognized by MCI.

    Error 263 for command:
        close E://PYTHON//Music.mp3
Failed to close the file: E://PYTHON//Music.mp3
Traceback (most recent call last):
  File "e:\PYTHON\Playsound.py", line 2, in <module>
    playsound('E://PYTHON//Music.mp3')
  File "C:\Users\HP\AppData\Local\Programs\Python\Python39\lib\site-packages\playsound.py", line 72, in _playsoundWin
    winCommand(u'open {}'.format(sound))
  File "C:\Users\HP\AppData\Local\Programs\Python\Python39\lib\site-packages\playsound.py", line 64, in winCommand
    raise PlaysoundException(exceptionMessage)
playsound.PlaysoundException:
    Error 263 for command:
        open E://PYTHON//Music.mp3
    The specified device is not open or is not recognized by MCI.
PS C:\Users\HP> & C:/Users/HP/AppData/Local/Programs/Python/Python39/python.exe e:/PYTHON/Playsound.py

    Error 263 for command:
        open E://PYTHON//Music.mp3
    The specified device is not open or is not recognized by MCI.

    Error 263 for command:
        close E://PYTHON//Music.mp3
    The specified device is not open or is not recognized by MCI.
Failed to close the file: E://PYTHON//Music.mp3
Traceback (most recent call last):
  File "e:\PYTHON\Playsound.py", line 2, in <module>
    playsound('E://PYTHON//Music.mp3')
  File "C:\Users\HP\AppData\Local\Programs\Python\Python39\lib\site-packages\playsound.py", line 72, in _playsoundWin
    winCommand(u'open {}'.format(sound))
  File "C:\Users\HP\AppData\Local\Programs\Python\Python39\lib\site-packages\playsound.py", line 64, in winCommand
    raise PlaysoundException(exceptionMessage)
playsound.PlaysoundException:
    Error 263 for command:
        open E://PYTHON//Music.mp3
    The specified device is not open or is not recognized by MCI.
Flock answered 26/7, 2021 at 14:5 Comment(0)
W
8

pip install playsound==1.2.2

The specified device is not open or is not recognized by MCI - playsound 1.3.0

Whyte answered 23/8, 2021 at 17:3 Comment(2)
This is actually what solved the issue for me. Try downgrading the playsound version to 1.22 and it will work!Bosco
I don't know what they did with playsound v1.3.0 but on my side, it cannot anymore play some wav files (no error code, just no sound) ... downgrading to v1.2.2 solved both issues...Further
G
2

I use Python 3.8.8 under Windows 10.

My audio file is D:\my\path\to\wav\mysound.wav

playsound ('mysound.wav') resulted in the 'The specified device is not open..' error mentioned above.

I tried to supply the full path, but later realized that os.path.dirname(__file__) returns a null string.

os.getcwd() returned the correct directory, but ran into a different issue: When I spliced the directory name with the file name, I got D:\my\path\to\wav\mysound.wav, but this also did not work with playsound. I got the error: 'Cannot specify extra characters after a string enclosed in quotation marks.'

Finally, I hardcoded the entire path using forward slashes: D:/my/path/to/wav/mysound.wav Now playsound() worked without issues.

This is only a quick and dirty solution, since my project is an experimental one. But the point I am trying to make is, playsound() is finicky with file names.

Garv answered 6/1, 2022 at 2:53 Comment(1)
You do not need to hard code ti. I used replace() to do it automaticaly. This is the code line from my pet project: fullPath:str = fr"{os.getcwd()}\{fileName}.{fileExtension}".replace("\\", "/")Pongid
I
2

In my case I simply use playsound('./' + audio_filename) because the audio and the .py file were in the same path or directory. You can use ../ to step back.

Inge answered 14/3, 2022 at 9:25 Comment(0)
F
1

I found the solution that we need to add the file to the same folder in which we have our current python program so we do need to add the path for the file

from playsound import playsound
playsound('Music.mp3')
Flock answered 22/8, 2021 at 10:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.