【发布时间】:2018-06-29 13:33:42
【问题描述】:
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 语句的语法错误。
知道我到底做了什么吗?
【问题讨论】: