属性尝试从麦克风获取输入时出错:__enter__



我一直在尝试使用speech_recognition 从python程序中的麦克风获取输入

我试着运行这个代码:-

import speech_recognition as sr
import pyaudio
r = sr.Recognizer()
with sr.Microphone as source:
audio = r.listen(source)
text = r.recognize_google(audio)
print(text)

但它不会运行。

上面写着:-

"C:UsersBravo SixAppDataLocalProgramsPythonPython37-32python.exe" "D:/BROTEEN/Works/Python/VALINI/speech testing.py"
Traceback (most recent call last):
File "D:/BROTEEN/Works/Python/VALINI/speech testing.py", line 9, in <module>
with sr.Microphone as source:
AttributeError: __enter__

进程结束,退出代码为1

我该如何解决这个问题???请帮我摆脱这种局面!!!

I Ctrl + clicked on the sr.**Microphone**, wherein I saw that it said it throws an attribute error when pyaudio 0.2.11 or later is not installed. So I installed it using cmd, but the problem still sustains... HELP!!!

同样的问题也发生在我身上,我通过如下编码解决了它:

with sr.Microphone() as source:
#your code here

我希望这能帮助解决你的问题。如果你仍然有一些问题,请告诉我。

我实际上认为Windows 7不容易与speech_recognition模块合作。。。所以我刚切换到Windows 10,现在它运行起来像黄油一样光滑!感谢

相关内容

  • 没有找到相关文章

最新更新