AttributeError:尝试从麦克风获取输入时__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:\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!!!


lflxyz 回答:AttributeError:尝试从麦克风获取输入时__enter__

我遇到了同样的问题,我通过像这样编码来解决了这个问题:

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

我希望这有助于解决您的问题。如果您仍然遇到问题,请告诉我。

,

我实际上认为Windows 7不能轻易与speech_recognition模块配合使用...所以我只是切换到Windows 10,现在它像黄油般平滑地工作!谢谢

本文链接:https://www.f2er.com/3108110.html

大家都在问