python - python语音识别中的AttributeError
问题描述
import speech_recognition as sr
r = sr.Recognizer()
with sr.Microphone as source:
print("Say something")
audio = r.listen(source)
voice_data = r.recognize_google(audio)
print(voice_data)
我正在尝试编译此代码,但它给出了这样的错误:-
Exception has occurred: AttributeError
__enter__
File "C:\Users\admin\Desktop\text to speech\speech to text.py", line 5, in
<module>
with sr.Microphone as source:
解决方案
你只需要使用sr.Microphone()
你忘记的括号。记住麦克风是一种方法。
推荐阅读
- angular - 角组件输入总是返回未定义
- ios - Metal:写入纹理并读取它而不调用 endEncoding
- sql - 我需要根据关键字查询数据库
- flutter - 我应该把开始运行一次的命令放在哪里?
- event-handling - Eclipse Rcp - 是否有推荐的方法来获取在处理程序中调用事件的父视图或编辑器?
- java - 使用多个正则表达式:按显示顺序一次打印一个匹配项
- amazon-web-services - 如何从 Lambda 中的警报事件中提取特定信息
- excel - 如何从雅虎财经下载限制为 100 行的数据
- javascript - JavaScript - 在另一个函数之外返回函数值
- winforms - Winform应用程序在某些变量包含数据后将数据添加到列表视图