import speech_recognition as sr
import pyttsx3
import datetime
r = sr.Recognizer()
mic = sr.Microphone()
engine = pyttsx3.init()
engine.setProperty('rate',120) #75 words per minute
engine.setProperty('volume',0.9) #loudness of speaker
def getTime():
str((datetime.datetime.now())
with mic as source:
audio = r.listen(source)
myInput = r.recognize_google(audio)
responses = {"hello":"hello there", "thanks":"don't mention it", "time":getTime}
if myInput in responses.keys():
engine.say(responses[myInput])
engine.runAndWait()
else:
engine.say("Sorry I don't understand that")
engine.runAndWait()
嘿,伙计们,我对python真的是个新手,我只是在搞这个。在我按下键盘上的CTRL+Z键撤销某些操作之前,一切都很顺利。我很确定我错过了Z,从那以后,我得到了with语句的语法错误
知道我到底做了什么吗
对不起!刚意识到getTime行中缺少一个括号
相关问题 更多 >
编程相关推荐