AttributeError: __enter__ while trying to take input from microphone

AttributeError: __enter__ while trying to take input from microphone

我一直在尝试使用 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:\Users\Bravo Six\AppData\Local\Programs\Python\Python37-32\python.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,现在它像黄油一样流畅!谢谢