我试着用SpeechRecognition 3.5把演讲变成文字。我正在使用Python2.7.13。我使用这个模块查找了一些示例,发现的所有示例包括:
r = sr.Recognizer()
with sr.Microphone() as source:
audio = r.listen(source)但是当我运行这个程序时,它总是会显示出这个错误。
AttributeError: __exit__我不知道如何解决这个问题,因为
with sr.Microphone() as source:正在寻找exit方法,但找不到。所以我试着去掉with关键字,所以看起来如下:
source = sr.Microphone()
audio = r.listen(source)但后来它朝我吐了个AssertionError。
AssertionError: Audio source must be entered before listening, see documentation for ``AudioSource``; are you using ``source`` outside of a ``with`` statement?我不知道从这里该怎么办。有人能解释一下为什么这不管用吗?
编辑:
sr.Microphone -> sr.Microphone()
编辑2:
这个错误是由于我没有导入PyAudio (这是必需的)而导致的,而且我没有意识到。现在我无法阻止它录下麦克风。
发布于 2017-04-20 15:10:05
加,phrase_time_limit=10 //10秒
例:
with sr.Microphone() as source:
print("Say something!")
audio = r.listen(source,timeout=1,phrase_time_limit=10)发布于 2019-10-13 04:27:53
以sr.Microphone为源:
print("say something!")
如果像这样写,那么就会出现属性错误,所以将sr.Microphone添加为sr.Microphone()
发布于 2020-05-12 07:41:16
使用
sr.Microphone() as source:而不是:
sr.Microphone as source:https://stackoverflow.com/questions/41359535
复制相似问题