![](/img/trans.png)
[英]Getting AttributeError: __enter__ when using Microphone from Speech Recognizer
[英]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 现在它像黄油一样光滑! 谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.