【问题标题】:I pressed something on my keyboard, now I'm receiving a syntax error for my with statement that was working perfectly beforehand我在键盘上按了一些东西,现在我收到一个语法错误,我的 with 语句事先运行良好
【发布时间】: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 语句的语法错误。

知道我到底做了什么吗?

【问题讨论】:

    标签: python syntax


    【解决方案1】:

    对不起!刚刚意识到我在 getTime 行上缺少括号

    【讨论】:

      猜你喜欢
      • 2015-02-16
      • 1970-01-01
      • 2021-09-18
      • 1970-01-01
      • 2022-11-02
      • 2019-03-12
      • 2011-07-23
      • 2015-07-15
      • 2011-05-14
      相关资源
      最近更新 更多