【发布时间】:2020-03-09 13:14:39
【问题描述】:
我一直在尝试使用 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,乍一看似乎你只是在使用类而不是麦克风对象 -
没听懂。我怎么做。我在youtube上关注了很多教程。!!!但问题仍然存在(顺便说一句,我在 Windows 7 上)
标签: python speech-recognition text-to-speech attributeerror microphone