我正在使用Python编写一个游戏,需要播放音效,所以我使用了playsound模块:
from playsound import playsound
playsound("Typing.wav", False)
Run Code Online (Sandbox Code Playgroud)
当我尝试运行该程序时,返回了此错误:
Error 263 for command:
open Typing.wav
The specified device is not open or is not recognized by MCI.
Run Code Online (Sandbox Code Playgroud)
我做了一些研究,一些消息来源表明这是我的声音驱动程序的问题。我更新并重新安装了它,但问题仍然存在。有什么办法可以解决这个问题吗?
我已经执行了 python pip installplaysound并且我的 Python 文件的位置也正确,请检查问题是什么?
它显示不能在用引号引起来的字符串后面指定额外的字符。
我的代码是:
from playsound import playsound
playsound('C:\\Users\\Lenovo\\OneDrive\\Documents\\Zoom\\1. Chapter 1\\play.mp3\\play.mp3')
Run Code Online (Sandbox Code Playgroud)
发生了错误:
声音发生地点:
请帮忙解决这个错误:
>>> from playsound import playsound
>>> playsound('C:\\Users\\Rohit\\Desktop\\Python\\file.mp3')
Run Code Online (Sandbox Code Playgroud)
终端结果:
PS C:\Users\Rohit\Desktop\Python> & C:/Users/Rohit/AppData/Local/Programs/Python/Python38/python.exe c:/Users/Rohit/Desktop/Python/2Python.py
Error 261 for command:
open "C:\Users\Rohit\Desktop\Python\file.mp3"
The driver cannot recognize the specified command.
Error 261 for command:
close "C:\Users\Rohit\Desktop\Python\file.mp3"
The driver cannot recognize the specified command.
Failed to close the file:
"C:\Users\Rohit\Desktop\Python\file.mp3"
Traceback (most recent call last):
File "c:/Users/Rohit/Desktop/Python/2Python.py", line 3, in <module>
playsound('C:\\Users\\Rohit\\Desktop\\Python\\file.mp3')
File "C:\Users\Rohit\AppData\Local\Programs\Python\Python38\lib\site-packages\playsound.py", line 72, in _playsoundWin
winCommand(u'open {}'.format(sound))
File "C:\Users\Rohit\AppData\Local\Programs\Python\Python38\lib\site-packages\playsound.py", line 64, in winCommand
raise PlaysoundException(exceptionMessage)
playsound.PlaysoundException:
Error 261 for command:
open …Run Code Online (Sandbox Code Playgroud) Collecting playsound\n Using cached playsound-1.3.0.tar.gz (7.7 kB)\n Installing build dependencies ... done\n Getting requirements to build wheel ... error\n error: subprocess-exited-with-error\n\n \xc3\x97 Getting requirements to build wheel did not run successfully.\n \xe2\x94\x82 exit code: 1\n \xe2\x95\xb0\xe2\x94\x80> [29 lines of output]\n Traceback (most recent call last):\n File "C:\\Users\\INTEL\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages\\pip\\_vendor\\pyproject_hooks\\_in_process\\_in_process.py", line 353, in <module>\n main()\n File "C:\\Users\\INTEL\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages\\pip\\_vendor\\pyproject_hooks\\_in_process\\_in_process.py", line 335, in main\n json_out[\'return_val\'] = hook(**hook_input[\'kwargs\'])\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File "C:\\Users\\INTEL\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages\\pip\\_vendor\\pyproject_hooks\\_in_process\\_in_process.py", line 118, in get_requires_for_build_wheel\n return hook(config_settings)\n ^^^^^^^^^^^^^^^^^^^^^\n File "C:\\Users\\INTEL\\AppData\\Local\\Temp\\pip-build-env-9ac5eef9\\overlay\\Lib\\site-packages\\setuptools\\build_meta.py", line 341, in get_requires_for_build_wheel\n return self._get_build_requires(config_settings, requirements=[\'wheel\'])\n …Run Code Online (Sandbox Code Playgroud) from playsound import playsound
playsound("1.mp3")
Run Code Online (Sandbox Code Playgroud)
上面使用playsound模块的代码会导致以下错误。如何解决?
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: …Run Code Online (Sandbox Code Playgroud) import speech_recognition as sr
import requests
from gtts import gTTS
from playsound import playsound
import os
import subprocess
bot_message = ""
message = ""
myobj = gTTS(text="Hello I am Shilpa Sheety Speak Anything I am Listening", lang='en', tld='com.au')
myobj.save("starting.mp3")
playsound("starting.mp3")
while bot_message !="Bye":
r = sr.Recognizer()
with sr.Microphone() as source:
audio = r.listen(source)
try:
message = r.recognize_google(audio)
print("You said : {}".format(message))
except:
print("Sorry Could not recognize your voice")
if len(message) == 0:
continue
print("Sending Message Now")
r = requests.post("http://localhost:5002/webhooks/rest/webhook", json={'message':message}) …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Playsound 播放代码文件夹中的文件,但是每次运行代码时,它似乎都能够调用该文件,但我总是收到以下输出:
playsound.PlaysoundException:
Error 277 for command:
open "para.mp3" alias playsound_0.9208788744295284
A problem occurred in initializing MCI.
Run Code Online (Sandbox Code Playgroud)
运行的代码只是playsound函数的使用:
from playsound import playsound
playsound("01. Humongous.mp3")
Run Code Online (Sandbox Code Playgroud)
我不确定这是否只是我的机器的问题还是我缺少的东西?
我也检查了路径变量,其他函数一切正常,但仅显示此模块的错误。代码:
from playsound import playsound
playsound('E://PYTHON//Music.mp3')
Run Code Online (Sandbox Code Playgroud)
以下是错误:
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 …Run Code Online (Sandbox Code Playgroud) 所以基本上这是我的代码:
from playsound import playsound
playsound('C:\\Users\\arnavb\\Desktop\\Python\\Lecture1\\song.mp3')
Run Code Online (Sandbox Code Playgroud)
我得到的错误是:
PS C:\Users\arnavb\Desktop\Python> & C:/Users/arnavb/AppData/Local/Programs/Python/Python39/python.exe c:/Users/arnavb/Desktop/Python/Lecture1/Practice_3.py
Error 305 for command:
open "C:\Users\arnavb\Desktop\Python\Lecture1\song.mp3"
Cannot specify extra characters after a string enclosed in quotation marks.
Error 263 for command:
close "C:\Users\arnavb\Desktop\Python\Lecture1\song.mp3"
The specified device is not open or is not recognized by MCI.
Failed to close the file: "C:\Users\arnavb\Desktop\Python\Lecture1\song.mp3"
Traceback (most recent call last):
File "c:\Users\arnavb\Desktop\Python\Lecture1\Practice_3.py", line 2, in <module>
playsound('C:\\Users\\arnavb\\Desktop\\Python\\Lecture1\\song.mp3')
File "C:\Users\arnavb\AppData\Local\Programs\Python\Python39\lib\site-packages\playsound.py", line 72, in _playsoundWin
winCommand(u'open {}'.format(sound))
File "C:\Users\arnavb\AppData\Local\Programs\Python\Python39\lib\site-packages\playsound.py", line 64, in winCommand
raise …Run Code Online (Sandbox Code Playgroud) 我在这里看到这个问题。但我的文件已经是wav格式了。我的代码是一个计时器,它在计时器结束后使用线程播放声音。它在那里不起作用,然后我在只有文件和库的不同文件中尝试了它:
from playsound import playsound
playsound('alarm.wav')
Run Code Online (Sandbox Code Playgroud)
当我执行此操作时,会发生以下错误:
Error 259 for command:
play alarm.wav wait
The driver cannot recognize the specified command parameter.
Traceback (most recent call last)
...
playsound.PlaysoundException:
Error 259 for command:
play alarm.wav wait
The driver cannot recognize the specified command parameter.
Run Code Online (Sandbox Code Playgroud)
但是当我给出路径时:
from playsound import playsound
playsound('path/to/alarm.wav')
Run Code Online (Sandbox Code Playgroud)
弹出框中出现以下错误(SyntaxError):
(unicode error)some stuff after that
Run Code Online (Sandbox Code Playgroud)
我在 Windows 上,在 IDLE 上通过双击文件(Python3.7.3)进行了尝试。
如果有帮助,它可以在不同的设备上运行(两者都有相同的 Python 版本)。
当我将 tkinter 与 Playsound 一起使用时,它会冻结直到播放声音。我尝试过使用 block = False 但它根本不播放声音!
这是我的代码的一部分:
from tkinter import *
from tkinter import ttk
from playsound import playsound
class GameMaker:
def __init__(self,root=None):
self.sounds={}
def AddSound(self,name,directory,overide=False,times=0,TimesOveride=0):
if times != 0:
name = name + str(times)
if TimesOveride != 0:
if times >= 10:
return None
else:
if times >= TimesOveride:
return None
try:
self.sounds[name]
if overide == True:
self.sounds[name]=directory
else:
AddSound(name,directory,times=times+1)
except:
self.sounds[name]=directory
def PlaySound(self,sound):
playsound(self.sounds[sound],block=False)
def MapAll(self,command):
keys = list("qwertyuiopasdfghjklzxcvbnm")
for key in keys:
self.Bind(key,command)
print(key) …Run Code Online (Sandbox Code Playgroud) python-playsound ×11
python ×10
python-3.x ×2
audio ×1
chatbot ×1
mci ×1
python-3.9 ×1
tkinter ×1
windows ×1