The specified device is not open or is not recognized by MCI

Question:

I was programming a game using Python and a sound effect needed to be played, so I used the playsound module:

from playsound import playsound

playsound("Typing.wav", False)

And when I attempted the run the program this error was returned:

Error 263 for command:
        open Typing.wav
    The specified device is not open or is not recognized by MCI.

I did some research and some sources indicated that it was an issue with my sound drivers. I updated & reinstalled it, but the issue persists. Is there any way to solve this?

Asked By: Richard Su

||

Answers:

I don’t think PlaySound supports .wav files. Try converting Typing.wav into an mp3 file. Then change

playsound("Typing.wav", False)

Into

playsound("Typing.mp3", False)
Answered By: RobbyDrSon

Try downgrading to Python 3.7 or 3.8

I had successfully used playsound in a project several months ago, but upon revisiting it today with a Python 3.9 virtual environment I ran into the same error as the OP. Downgrading to either a Python 3.7 or 3.8 venv fixed things right up.

I know this feels like a cheap answer, and I don’t like it either, especially since playsound‘s CI system explicitly does a build for Python 3.9 on Windows, Linux, and Mac. If someone else has more insight into why playsound doesn’t seem to work in Python >3.8 I’d love to hear it!

Answered By: thehale

I had this same problem and fixed it using

audio_file = os.path.dirname(__file__) + 'audio.mp3'
playsound(audio_file)
Answered By: felipecapp

I faced this problem too firstly as mentioned in the previous comments I downgraded my python version from 3.10 to 3.7 and yet the problem persisted.
So what actually worked is that the recent versions of playsound are giving such errors in order to fix this run the following commands in cmd as admin

pip uninstall playsound

pip install playsound==1.2.2

and this should do the work.

just in case that doesn’t work try degrading your python version to 3.7 and run these commands and that should be good.

Answered By: Jai advith

Please see my answer here:
The problem is in the way playsound() handles file paths. It expects a full path name using forward slashes only. Wish it becomes more portable in subsequent releases.

Answered By: Raja

**Command run as administrator

  1. pip uninstall playsound
  2. pip install playsound==1.2.2

**terminal in Pycharm

  1. pip uninstall playsound
  2. pip install playsound==1.2.2
Answered By: SaiKe

This worked for me:

from pathlib import Path

from playsound import playsound

audio = Path().cwd() / "audio.mp3"
playsound(audio)
Answered By: clamytoe

Just use playsound2 instead. Everything’s the same except this library is not buggy.

Answered By: eLeMeNOhPi

Using VLC

Hey so I have got a fix this error without degrading Python version.

We will use the vlc library.

Firstly we import the library into our project.

import vlc

Next we initialise the vlc

media = vlc.MediaPlayer(‘file_name.type’)

Finally we will execute the audio to play

media.play()

Full Code

import vlc
media = vlc.MediaPlayer('audio.mp3)
media.play()
Answered By: unofficialdxnny

I explored and find the solution that this helped me

audio_file = os.path.dirname(__file__) + 'Switch.mp3'
playsound(audio_file)`
Answered By: Mritunjay
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.