Python playsound 오류 - Python playsound olyu

파이썬에서 간단히 오디오 파일을 재생해야 하는 경우 playsound 라이브러리를 활용할 수 있습니다. 사용법은 이전 글을 참고해주세요. 

- [python] playsound 모듈로 음악 재생하기  

그런데 최근에 이 라이브러리(버전 1.3.0)를 설치해서 테스트해봤는데 오디오 파일 재생이 안 되면서 다음과 같은 에러가 발생했습니다. 

Error 259 for command:
        play ./white-noise.wav wait
    지정한 명령 매개 변수를 드라이버가 인식할 수 없습니다.

    Error 263 for command:
        close ./white-noise.wav
    지정한 장치가 열려 있지 않거나 MCI에서 인식되지 않습니다.
Failed to close the file: ./white-noise.wav
Traceback (most recent call last):
  File "C:\Users\사용자명\Desktop\enjoy_python\ex6\ex6_4.py", line 30, in audio1_btn_clicked
    playsound("./white-noise.wav")
  File "C:\Users\사용자명\Desktop\enjoy_python\ex6\.venv\lib\site-packages\playsound.py", line 73, in _playsoundWin
    winCommand(u'play {}{}'.format(sound, ' wait' if block else ''))
  File "C:\Users\사용자명\Desktop\enjoy_python\ex6\.venv\lib\site-packages\playsound.py", line 64, in winCommand
    raise PlaysoundException(exceptionMessage)
playsound.PlaysoundException:
    Error 259 for command:
        play ./white-noise.wav wait
    지정한 명령 매개 변수를 드라이버가 인식할 수 없습니다.

이 에러 해결을 위해서 제가 취한 것은 버전을 1.2.2로 내린 것(downgrade)입니다. 

pip install playsound==1.2.2

그랬더니 해당 예외가 발생하지 않고 음악이 재생되었습니다. 

I'm trying to play a sound with the python library soundplay.

I saw other questions on Stack Overflow, but I haven't found a valid solution for my problem.

Here is the piece of code that should play the sound:

from playsound import playsound

playsound('./folder/sound.mp3')

This is the error:

playsound.PlaysoundException:
    Error 263 for command:
        open ./folder/sound.mp3
    The specified device is not open or is not recognized by MCI

I've also tried uninstalling pysound and installing its latest version, but the error doesn't change.

Does anyone have a solution?🤔

Andrea M

2,2041 gold badge8 silver badges26 bronze badges

asked Aug 5 at 16:26

It's probably a file system issue. When the code runs in the playsound module, it doesn't recognize the relative path you entered. Instead, you need to enter an absolute path.

Try:

import os
current_dir = os.getcwd()
file_path = current_dir + '/folder/sound.mp3'

Alternatively:

import os
file_dir = os.path.dirname('./folder/sound.mp3')
file_path = file_dir + '/sound.mp3'

answered Aug 6 at 9:39

Python playsound 오류 - Python playsound olyu

OmriOmri

4133 silver badges12 bronze badges

1

I had already used playsound in several projects to run audio files. When I tried to run one of my old projects it resulted in an error, I figured out that it is caused by playsound. Even a simple code results in an error, can anyone tell me how to run the audio files with playsound? any help is appreciable :)

note: punch.mp3 is located in the same directory and am currently using python 3.9

code:

from playsound import playsound

playsound("PUNCH.mp3")

output:

Error 275 for command:

open PUNCH.mp3

Cannot find the specified file. Make sure the path and filename are correct.

Error 263 for command:

close PUNCH.mp3

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

Failed to close the file: PUNCH.mp3

Traceback (most recent call last):

File "d:\programming\Python\test.py", line 3, in <module>

playsound("PUNCH.mp3")

File "C:\Users\Erlik\AppData\Local\Programs\Python\Python39\lib\site-packages\playsound.py", line 72, in _playsoundWin

winCommand(u'open {}'.format(sound))

File "C:\Users\Erlik\AppData\Local\Programs\Python\Python39\lib\site-packages\playsound.py", line 64, in winCommand

raise PlaysoundException(exceptionMessage)

playsound.PlaysoundException:

Error 275 for command:

open PUNCH.mp3

Cannot find the specified file. Make sure the path and filename are correct.

Output: modulenotfounderror:no module named 'gi'

Yup you need to install module gi or maybe the name is wrong

It is playsound not Playsound also for gi ,the actual module name is pgi or gi ,I really can't tell even after researching a lot about it on Google

You could search for the required library depending on the platform you're using if you don't have them and it wouldn't be that hard

You can use thinkdsp library and make_audio function for make a sound....

When I pip install gi it says could not find a version that satisfies the requirement gi (from versions:) no matching distribution found for gi And when I tried to import playsound with the p as a capital letter I got an error that said modulenotfounderror:no module named 'Playsound'

Could it be happening because I'm using android?

Traceback (most recent call last): File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 31, in <module> start(fakepyfile,mainpyfile) File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 30, in start exec(open(mainpyfile).read(), __main__.__dict__) File "<string>", line 3, in <module> File "/data/user/0/ru.iiec.pydroid3/files/arm-linux-androideabi/lib/python3.7/site-packages/playsound.py", line 91, in _playsoundNix import gi ModuleNotFoundError: No module named 'gi' [Program finished]

/storage/emulated/0 $ pip install gi Collecting gi Could not find a version that satisfies the requirement gi (from versions: ) No matching distribution found for gi /storage/emulated/0 $

Traceback (most recent call last): File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 31, in <module> start(fakepyfile,mainpyfile) File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 30, in start exec(open(mainpyfile).read(), __main__.__dict__) File "<string>", line 1, in <module> ModuleNotFoundError: No module named 'Playsound' [Program finished]

Traceback (most recent call last): File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 31, in <module> start(fakepyfile,mainpyfile) File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 30, in start exec(open(mainpyfile).read(), __main__.__dict__) File "<string>", line 3, in <module> NameError: name 'Playsound' is not defined [Program finished]

Nicolas okiokpa if you have solved then please tell again the whole process how you have solved in Android