Error when trying to play audio using playsound

Asked 2 years ago, Updated 2 years ago, 354 views

When I use playsound in the Jupiter Notebook and do the following, I get an error.
It worked once, but it didn't work from the second time.

Code executed:

wf.write('mix_1.wav', rate1,y[0])
wf.write('mix_2.wav', rate2,y[1])
wf.write('mix_3.wav', rate3,y[2])

error:

PermissionError: [Errno13] Permission denied: 'mix_1.wav'

Another error followed by executing the following code:Is there anything to do with it?Please tell me how to solve it.

Code executed:

from playsound import playsound

playsound("mix_1.wav")

error:

Error 265 for command:
        open mix_1.wav
    The device name is already used as an alias in this application.Use a unique alias.

python python3 jupyter-notebook

2022-09-30 22:00

1 Answers

It may be similar to the following script found in the search for subsequent questions: Sound separation by independent component analysis, i.e., wf.write('mix_1.wav', rate1,y[0]) instead of playaround.

And when I run it as a script file with Windows 10 64-bit Python's original interpreter, it works no matter how many times I try it.

import numpy as np
import scipy.io.wavfile as wf

rate1,data1 = wf.read('loop1.wav')
rate2,data2 = wf.read('string.wav')
rate3,data3 = wf.read('fanfare.wav')
if rate1! = rate2 or rate2! = rate3:
    raise ValueError('Sampling_rate_Error')

mix_1 = data1 * 0.6 + data2 * 0.3 + data3 * 0.1
mix_2 = data1*0.3 + data2*0.2 + data3*0.5
mix_3 = data1*0.1 + data2*0.5 + data3*0.4
y=[mix_1, mix_2, mix_3]
y = [(y_i*32767/max(np.absolute(y_i))).astype(np.int16)for y_in np.asarray(y)]

wf.write('mix_1.wav', rate1,y[0])
wf.write('mix_2.wav', rate2,y[1])
wf.write('mix_3.wav', rate3,y[2])

So if your operating system is not Windows, it may depend on the operating system or how you use it in JupyterNotebook.

Why don't you close the appropriate Notebook and reset the environment, exit and restart JupyterNotebook and then run the script again?
So if the first run works properly, you can use JupyterNotebook and if there is a problem with the first run, you can use it.

Alternatively, try comparing the results with the original Python instead of JupyterNotebook as above.

For the latter playsound, the .wav file will be played on the original interpreter of Windows 10 64-bit Python, but the following close will fail at the end:

 C:\Develop\Python>py playwav.py

    Error 263 for command:
        close mix_1.wav
    The specified device is not open or is not recognized by the MCI.
Failed to close the file: mix_1.wav

C:\Develop\Python>

If you run interactive instead of script and run playsound again after the error occurs, you will receive a similar error to the question.
However, it does not occur only once, but instead close erroropen errorclose erroropen error.

 C:\Develop\Python>py
Python 3.9.7 (tags/v3.9.7:1016ef3, Aug 30 2021, 20:19:38) [MSC v.1929 64bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from playsound import playsound
>>
>> playsound("mix_1.wav")

    Error 263 for command:
        close mix_1.wav
    The specified device is not open or is not recognized by the MCI.
Failed to close the file: mix_1.wav
>> playsound("mix_1.wav")

    Error 265 for command:
        open mix_1.wav
    The device name is already used as an alias in this application.Use a unique alias.

    Error 263 for command:
        close mix_1.wav
    The specified device is not open or is not recognized by the MCI.
Failed to close the file: mix_1.wav
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python39\lib\site-packages\playsound.py", line 72, in_playsoundWin
    winCommand(u'open{}'.format(sound))
  File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python39\lib\site-packages\playsound.py", line64, in winCommand
    raise PlaysoundException(exceptionMessage)
playsound.PlaysoundException:
    Error 265 for command:
        open mix_1.wav
    The device name is already used as an alias in this application.Use a unique alias.
>>

So you can think of one of the following:

  • playsoundNewly Found Bug
  • playsound is not working
  • .wav Something is wrong with the file
  • Incompatible or mixed issue with Windows 10 updates at some point

playsoundAdditional information:

In Windows 10 64-bit Python 3.9.7, lowering the playsound version to 1.2.2 is no longer a problem with this article.
From 1.3.0?It seems to be a bug that has entered or surfaced.
What is the error in the code for this play sound module event through the syntax is same as on official site?

pip install playsound==1.2.2

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

Comment: This is actually what resolved the issue for me.Try downgrading the playsound version to 1.22 and it will work!

PermissionError Added:

I don't know what's going on, but it seems that Unix-like things are common because the permissions don't match as the folder owner and the error message say.
Cannot open new Jupiter Notebook [Permission Denied]
Jupyter notebook permission error

Even Windows seems to have a similar story.
I would like to resolve kernel errors in the jupyter notebook
PermissionError: [Errno13]Permission denied#4907

Also, this is WSL on Windows, so it's Unix-like.
PermissionError: [Errno13] Permission denied when running jupyter notebook on bash#3608


2022-09-30 22:00

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.