首页 > 解决方案 > 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:

标签: python

解决方案


你只需要使用sr.Microphone()你忘记的括号。记住麦克风是一种方法。


推荐阅读