【发布时间】:2018-03-09 16:00:57
【问题描述】:
从 gtts 导入 gTTS 导入操作系统 将语音识别导入为 sr 导入浏览器 进口时间
def talkToME(音频字符串): 打印(音频字符串) tts=gTTS(text=audioString, lang='en') tts.save('audio.mp3') os.system('mpg123 audio.mp3')
监听命令
def myCommand():
r = sr.Recognizer()
with sr.Microphone as source:
print('Say Something!')
r.pause_threshold = 1
r.adjust_for_ambient_noise(source, duration =1)
audio = r.listen(source)
try:
command = r.recognise_google(audio)
print('you said: ' + command+ '/n')
#loop back to continue listen for commands
except sr.UnknownvalueError:
assistant(myCommand())
return command
#if statements for executing commands
def assistant(command):
if "how are you" in command:
talkToMe("i am fine")
time.sleep(2)
talkToMe(' hi brian, what can i do for you?')
while True:
command = recordAudio()
assistant(myCommand())
这是我的代码。但是,当我运行它时,没有错误消息,似乎什么也没有发生。我有点迷失了什么是错的。它应该回答“我很好”,但没有任何反应。我正在使用 Windows 10. 和 python 3.6.3 该代码似乎适用于linux。但我不知道为什么?即使是这样,如何编辑或编写代码来使用python为windows创建一个简单的jarvis。 谢谢。
【问题讨论】:
标签: python windows-10