1

我正在研究基于语音的人工智能(比如钢铁侠电影中的贾维斯)。我希望它做的一件事是听我说"search something123"并将“搜索”这个词识别为命令。听到此命令后,它应该启动 google chrome 并搜索短语的其余部分(在本例中为“something123”)。

有谁知道如何让我的脚本将“搜索”这个短语识别为命令?我正在用 applescript 编码并使用 MAC 语音识别。

4

3 回答 3

2

好吧,我一直在努力做和你一样的事情。(对不起,我回答得有点晚了)我发现如果你安装了“Ok Google”,你可以使用它,如果没有,这是一个应该工作的脚本。请记住,它并不完美,但比我发现的要简单得多。

tell application "Google Chrome" 
    close active tab of window 1
end tell

tell application "Google Chrome"
    activate
    set myTab to make new tab at end of tabs of window 1
    set URL of myTab to "http://google.com"
    delay 3
    tell application "Google Chrome" to activate
    tell application "System Events"
            key code 47 using {command down, shift down}
    end tell
end tell
于 2013-12-19T00:49:48.850 回答
1

看起来您需要指定您要寻找用户说的内容,因此对于“您要搜索什么?”之类的问题。您需要告诉 SpeechRecognitionServer 您希望输入是什么(在字符串列表中)。我将一些示例代码放在一起,以便您了解它是如何工作的,但我很确定这是您可以得到的最接近您正在尝试做的事情。但是,如果您要使用 SpeechRecognitionServer,我强烈建议您查看该库。

on format_string(myString)
    set AppleScript's text item delimiters to " "
    set myString to text items of myString
    set AppleScript's text item delimiters to "%20"
    set myString to myString as string
    set AppleScript's text item delimiters to ""
    return myString
end format_string

tell application "SpeechRecognitionServer"
    set theResponse to listen for {"Yes", "no"} with prompt "Would you like to search?"
    if theResponse is "Yes" then
        say "What would you like to search?"
        set toSearch to text returned of (display dialog "What would you like to search?" default answer "tacos")
        set toSearch to format_string(toSearch)
        tell application "Safari"
            open location "http://www.google.com/#output=search&q=" & toSearch
        end tell
    else
        say "Thanks for stopping by"
    end if
end tell
于 2013-07-29T19:53:27.977 回答
0

我使用 Google 语音搜索功能的脚本应该可以帮助您入门...

于 2013-07-29T19:52:14.567 回答