简体   繁体   中英

Sound file will not play using playsound module python error 259

from playsound import playsound

playsound("1.mp3")

The code above using the playsound module results in the following errors. How to resolve?

    Error 259 for command:
        play 1.mp3 wait
    The driver cannot recognize the specified command parameter.

    Error 263 for command:
        close 1.mp3
    The specified device is not open or is not recognized by MCI.
Failed to close the file: 1.mp3
Traceback (most recent call last):
  File "C:\Users\itsra\OneDrive\Desktop\Python\test.py", line 4, in <module>
    playsound("1.mp3")
  File "C:\Users\itsra\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\playsound.py", line 73, in _playsoundWin
    winCommand(u'play {}{}'.format(sound, ' wait' if block else ''))
  File "C:\Users\itsra\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\playsound.py", line 64, in winCommand
    raise PlaysoundException(exceptionMessage)
playsound.PlaysoundException:
    Error 259 for command:
        play 1.mp3 wait
    The driver cannot recognize the specified command parameter.

I also got the same problem. Try downgrading playsound version. Use

pip install playsound==1.2.2

This solved it.

I also faced a similar problem. Try converting into a wav file. It worked for me and I think the problem is because of the lack of information about the bit rate of the music in the file. enter image description here

这个版本的 Pyaudio 对我有用: pip install playsound==1.2.2

Solution 1:

I got this error & downgraded to 1.2.2 (from 1.3.0) as suggested in other comments & it worked.

Solution 2:

The other solution that I tried (v 1.3.0) is to rename the file & it worked.

I get the error if file name = "lost_money.mp3" or "money_lost.mp3"

But not: "lost money.mp3" or "transaction_failed.mp3" or "made_profit.mp3"

playsound library is simple to use but it does not support some audio formats. This solution works for all type of formats

from mutagen.mp3 import MP3
import time
import miniaudio

file='1.mp3'
audio = MP3(file)
length=audio.info.length
stream = miniaudio.stream_file(file)

with miniaudio.PlaybackDevice() as device:
    device.start(stream)
    print('playing')
    time.sleep(length)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM