skip to Main Content

I’m working on a voice-based artificial intelligence (like Jarvis from the Iron Man movies). One of the things I want it to do is listen to me say "search something123" and recognize the word ‘search’ as a command. After hearing this command it should to launch google chrome and search for the rest of the phrase (‘something123’ in this case).

Does anyone know how I can make my script recognize the phrase “search” as a command? I’m coding in applescript and using the MAC speech recognition.

3

Answers


  1. My script which uses Google’s voice search feature should get you started…

    Login or Signup to reply.
  2. It looks like you need to specify what it is you’re looking for the user to say, so for a question like “What do you want to search for?” you would need to tell SpeechRecognitionServer what you want the input to be (In a list of strings). I threw together some sample code so you could see how it works, but I’m pretty sure this is the closest you can get to what you’re trying to do. If you’re going to be using SpeechRecognitionServer though, I strongly recommend looking at the library.

    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
    
    Login or Signup to reply.
  3. Well I have been trying to do the same as you. (sorry I’m a tad-bit late at answering) What I found is that you can use “Ok Google” if you have that installed if not, here is a script that should work. Keep in mind it’s not perfect but much simpler than what i’ve found.

    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
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search