【发布时间】:2019-12-22 00:21:57
【问题描述】:
我正在尝试用Python制作一个简单的语音识别工具,并尝试了以下代码:
import speech_recognition as sr
r = sr.Recognizer()
with sr.Microphone as source:
print ("Speak into the microphone")
audio = r.listen(source)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-4-10651df1693e> in <module>
----> 1 with sr.Microphone as source:
2 print ("Speak into the microphone")
3 audio = r.listen(source)
AttributeError: __enter__
我希望有人能够说明在这种情况下如何使用__enter__ 属性?
非常感谢!
【问题讨论】:
-
这意味着
sr.Microphone不支持上下文管理器。我不知道图书馆,所以你必须自己调查一下
标签: python python-3.x attributes speech-recognition microphone