[英]__enter__ error using google's speech api python3
我正在使用 google 的 API 在 python 中制作一个语音识别器项目。 代码如下:
from gtts import gTTS
import speech_recognition as sr
def get_audio():
r = sr.Recognizer()
with sr.Microphone as source:
l = r.listen(source)
said = ""
try:
said = recognize_google(l)
print(said)
except Exception as e:
print("Exception: " + str(e))
return said
get_audio()
错误是:
<ipython-input-5-73a42a1f9208> in get_audio()
1 def get_audio():
2 r = sr.Recognizer()
----> 3 with sr.Microphone as source:
4 l = r.listen(source)
5 said = ""
AttributeError: __enter__
有人可以解释为什么吗? 一个人拥有相同的代码,并且在他的电脑上运行。
用
with sr.Microphone() as source:
...
注意括号:这是一个函数调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.