我正在尝试使用语音识别和pyttsx3模块在python中编写jarvis。由于错误,我卡住了Attribute error:__enter__
我不明白为什么会这样。我是蟒蛇的新手。目前我正在使用python 3.8。
def takeCommmand():
r = sr.Recognizer()
with sr.Microphone as source:
print("listening...")
r.pause_threshold = 1
audio = r.listen(source)
return
错误:
File "c:/Users/Dell/Desktop/jarvis voice assistant/jarvis.py", line 28, in takeCommmand
with sr.Microphone as source:
AttributeError: __enter__
请告诉我代码有什么问题。
试试这个:
def takeCommmand():
r = sr.Recognizer()
with sr.Microphone() as source: # <--- look here
print("listening...")
r.pause_threshold = 1
audio = r.listen(source)
return
您需要添加()
才能使其正常工作。