0

我也检查了路径变量,其他功能一切正常,但仅显示此模块的错误。代码:

from playsound import playsound
playsound('E://PYTHON//Music.mp3')

以下是错误:

PS C:\Users\HP> & C:/Users/HP/AppData/Local/Programs/Python/Python39/python.exe e:/PYTHON/Playsound.py

    Error 263 for command:
        open E://PYTHON//Music.mp3
    The specified device is not open or is not recognized by MCI.

    Error 263 for command:
        close E://PYTHON//Music.mp3
Failed to close the file: E://PYTHON//Music.mp3
Traceback (most recent call last):
  File "e:\PYTHON\Playsound.py", line 2, in <module>
    playsound('E://PYTHON//Music.mp3')
  File "C:\Users\HP\AppData\Local\Programs\Python\Python39\lib\site-packages\playsound.py", line 72, in _playsoundWin
    winCommand(u'open {}'.format(sound))
  File "C:\Users\HP\AppData\Local\Programs\Python\Python39\lib\site-packages\playsound.py", line 64, in winCommand
    raise PlaysoundException(exceptionMessage)
playsound.PlaysoundException:
    Error 263 for command:
        open E://PYTHON//Music.mp3
    The specified device is not open or is not recognized by MCI.
PS C:\Users\HP> & C:/Users/HP/AppData/Local/Programs/Python/Python39/python.exe e:/PYTHON/Playsound.py

    Error 263 for command:
        open E://PYTHON//Music.mp3
    The specified device is not open or is not recognized by MCI.

    Error 263 for command:
        close E://PYTHON//Music.mp3
    The specified device is not open or is not recognized by MCI.
Failed to close the file: E://PYTHON//Music.mp3
Traceback (most recent call last):
  File "e:\PYTHON\Playsound.py", line 2, in <module>
    playsound('E://PYTHON//Music.mp3')
  File "C:\Users\HP\AppData\Local\Programs\Python\Python39\lib\site-packages\playsound.py", line 72, in _playsoundWin
    winCommand(u'open {}'.format(sound))
  File "C:\Users\HP\AppData\Local\Programs\Python\Python39\lib\site-packages\playsound.py", line 64, in winCommand
    raise PlaysoundException(exceptionMessage)
playsound.PlaysoundException:
    Error 263 for command:
        open E://PYTHON//Music.mp3
    The specified device is not open or is not recognized by MCI.
4

3 回答 3

2

pip install playsound==1.2.2

指定设备未打开或 MCI 无法识别 - playsound 1.3.0

于 2021-08-23T17:03:44.170 回答
1

我找到了我们需要将文件添加到我们当前的 python 程序所在的同一文件夹的解决方案,因此我们确实需要添加文件的路径

from playsound import playsound
playsound('Music.mp3')
于 2021-08-22T10:52:06.197 回答
0

我在 Windows 10 下使用 Python 3.8.8。

我的音频文件是 D:\my\path\to\wav\mysound.wav

playsound ('mysound.wav')导致上面提到的“指定的设备未打开..”错误。

我试图提供完整的路径,但后来意识到os.path.dirname(__file__)返回一个空字符串。

os.getcwd()返回了正确的目录,但遇到了另一个问题:当我将目录名与文件名拼接时,我得到了D:\my\path\to\wav\mysound.wav,但这也不适用于playsound. 我收到错误消息:“不能在用引号括起来的字符串后指定额外的字符。”

最后,我使用正斜杠对整个路径进行了硬编码:D:/my/path/to/wav/mysound.wav 现在可以正常playsound()工作了。

这只是一个快速而肮脏的解决方案,因为我的项目是一个实验性的项目。但我想说的是,playsound()文件名很挑剔。

于 2022-01-06T02:53:42.983 回答