【问题标题】:Searching Chrome with speech input使用语音输入搜索 Chrome
【发布时间】: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() 真的运行了吗?我不认为Applicationchrome.exe 的正确可执行文件,%s 似乎放错了位置
  • 所以我应该能够说出一个 site.com 的词,而 Jarvis 应该在新标签页中打开该网站,但他只是从头开始。跨度>
  • 请编辑您的帖子而不是评论,以将您的完整代码包含为minimal reproducible example

标签: python speech-recognition


【解决方案1】:

我想通了。我需要将反斜杠 (\) 更改为正斜杠 (/) 并将 chrome.exe 添加到路径行的末尾。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-02-22
    • 2018-06-19
    • 1970-01-01
    • 1970-01-01
    • 2020-11-03
    • 1970-01-01
    • 1970-01-01
    • 2019-11-30
    相关资源
    最近更新 更多