【发布时间】:2021-09-06 17:32:11
【问题描述】:
我正在学习 Udemy 课程来创建像 Jarvis 这样的 AI。他接受命令并使用它们来完成任务。我无法让他在 chrome 中搜索。
import pyttsx3
import speech_recognition as sr
import webbrowser as wb
engine = pyttsx3.init()
def speak(audio):
engine.say(audio)
engine.runAndWait()
def wishme():
speak("Welcome back Summer.")
speak("Jarvis at your service. How may I help you today?")
def TakeCommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
r.pause_threshold = 1
audio = r.listen(source)
try:
print("Recognizing...")
query = r.recognize_google(audio,language='en.US')
print(query)
except Exception as e:
print(e)
print("Say that again please...")
return "None"
return query
if __name__ == "__main__":
wishme()
while True:
query = TakeCommand().lower()
if 'search in chrome' in query:
speak("What should I search?")
chromepath = 'C:\Program Files\Google\Chrome\Application %s'
search = TakeCommand().lower()
wb.get(chromepath).open_new_tab(search+'.com')
我在最后一个 if 语句和让 Jarvis 接受命令时遇到问题,然后在 chrome 中打开一个新选项卡并搜索我让他搜索的内容。
【问题讨论】:
-
请澄清“不工作”...是否输入了 elif 语句? TakeCommand() 真的运行了吗?我不认为
Application是chrome.exe的正确可执行文件,%s似乎放错了位置 -
所以我应该能够说出一个 site.com 的词,而 Jarvis 应该在新标签页中打开该网站,但他只是从头开始。跨度>
-
请编辑您的帖子而不是评论,以将您的完整代码包含为minimal reproducible example