[英]jarvis ai building in python for windows
from gtts import gTTS import os import speech_recognition as sr import webbrowser import time 从gtts导入gTTS导入os导入Speech_recognition为sr导入Web浏览器导入时间
def talkToME(audioString): print(audioString) tts=gTTS(text=audioString, lang='en') tts.save('audio.mp3') os.system('mpg123 audio.mp3') def talkToME(audioString):print(audioString)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())
this is my code. 这是我的代码。 however, when i run it there is no error message and nothing seems to happen.
但是,当我运行它时,没有错误消息,似乎什么也没有发生。 i am kind of lost whats wrong.
我有点错了。 it was supposed to answer "I am fine" but nothing happens.
它应该回答“我很好”,但是什么也没发生。 i am using windows 10. and python 3.6.3 the code seems to be for linux.
我正在使用Windows 10.和python 3.6.3,代码似乎是针对linux的。 but i dont know why?
但我不知道为什么? and even if so how can edit or write a code for creating a simple jarvis for windows using python.
即使是这样,如何使用python编辑或编写代码来为Windows创建简单的jarvis。 thank you.
谢谢。
Try changing the following lines to get results: 尝试更改以下行以获得结果:
sr.Microphone
to sr.Microphone()
and r.recognise_google(audio)
to r.recognize_google(audio)
sr.Microphone
到sr.Microphone()
和r.recognise_google(audio)
到r.recognize_google(audio)
Please tell me if this works cause it worked for me. 请告诉我这个方法是否对我有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.