使用applescript进行语音搜索 - 如何识别命令?

时间:2013-07-29 19:24:28

标签: speech-recognition

我正在研究基于语音的人工智能(如钢铁侠电影中的贾维斯)。我希望它做的一件事就是听我说"search something123"并将'搜索'这个词识别为命令。听到这个命令后,它应该启动谷歌浏览器并搜索其余的短语(在这种情况下为'something123')。

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

3 个答案:

答案 0 :(得分:1)

我一直在尝试和你一样。 (对不起,我回答的时间有点迟了)我发现你可以使用“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

答案 1 :(得分:0)

使用Google语音搜索功能的

My script可以让您入门......

答案 2 :(得分:0)

看起来你需要指明用户要说的是什么,所以对于诸如“你想要搜索什么?”之类的问题。您需要告诉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