Search code examples
applescriptruntime-errorspeech-recognitionapplescript-objcappleevents

how to prevent or extend AppleEvent or SpeechRecognitionServer timed out?


I am working on a SpeechRecognition project and I am pretty much done. However, there is one thing I cant quite figure out. When I launch my application it listens to my commands, and if I stay quite or don't say the commands then it is giving me this Script Error: enter image description here it is timing out. I want it to stay open 24 hour even if I am not saying anything.

This is my code:

tell application "SpeechRecognitionServer"
    with timeout of 10000 seconds
        set FRIDAY_AI to listen for commands
    end timeout
end tell

If you could help me solve this problem I would really appreciate it.

Thank you!


Solution

  • About 70% of everything I do on my computer is controlled by dictation commands and my own custom dictation commands. Very powerful stuff once you get the hang of it. I set you up with a small script with a few examples to have the SpeechRecognitionServer app continuously listen for a set of spoken commands to act upon. I think it's pretty self-explanatory by looking at the code to be able to adjust it to your needs.

    In Script Editor, save this following code as a stay open application. Make sure to add your new app in System Preferences to the list of apps allowed to control your computer. Now all you need to do is launch your new app.

    on idle
        try
            tell application "SpeechRecognitionServer"
                set theChoice to listen continuously for ¬
                    {"Open Google", "Close Windows", "Enter Name", "Enter Password", "Close My Commands"} ¬
                        with identifier "mine" with section title "WeeeHaaa's Commands"
    
                if theChoice is "Open Google" then
                    tell application "Google Chrome" to activate
                else if theChoice is "Close Windows" then
                    tell application "Finder" to close windows
                else if theChoice is "Enter Name" then
                    set myFullname to "Crazy Eddie"
                    tell application "System Events"
                        keystroke myFullname
                    end tell
                else if theChoice is "Enter Password" then
                    set myPassword to "secretpassword"
                    tell application "System Events"
                        keystroke myPassword
                    end tell
                else if theChoice is "Close My Commands" then
                    quit me
                end if
    
            end tell
        end try
        return 0.5
    end idle
    
    on quit
        -- stop listening
        tell application "SpeechRecognitionServer"
            stop listening for identifier "mine"
        end tell
        continue quit
    end quit
    

    enter image description here

    enter image description here