Sound file will not play using playsound module python error 259
Asked Answered
L

5

8
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.
Laceration answered 5/9, 2021 at 16:58 Comment(3)
Are the python script and 1.mp3 are in the same folder?Sanders
Yes they are in the same folder.Laceration
Are you having this problem with other mp3 files or just this one?Roodepoortmaraisburg
E
16

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

pip install playsound==1.2.2

This solved it.

Evonevonne answered 5/10, 2021 at 6:7 Comment(0)
D
0

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

Danielledaniels answered 18/9, 2021 at 15:20 Comment(0)
L
0

This version of Pyaudio worked for me : pip install playsound==1.2.2

Lenlena answered 31/5, 2022 at 11:57 Comment(0)
S
0

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"

Sensillum answered 6/7, 2022 at 16:38 Comment(1)
yes but it works when u reinstall version 1.3 after 1.2.2Janel
S
0

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)

Somatoplasm answered 11/9, 2022 at 7:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.