[英]jarvis ai building in python for windows
从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 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。 谢谢。
尝试更改以下行以获得结果:
sr.Microphone
到sr.Microphone()
和r.recognise_google(audio)
到r.recognize_google(audio)
请告诉我这个方法是否对我有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.