Talymo31
Talymo31

Reputation: 31

AppleScript Speech Recognition Server to listen to any response

Ok, currently, I have a script that looks like this:

tell application "SpeechRecognitionServer"
    set theResponse to listen for {"Mark"} with prompt "What is your name?"
end tell

However, I do not want it to listen to a particular keyword. I want it to gather the voice data from that prompt and turn it into a string that I can store in my database.

So, for instance, the user would be prompted with the spoken question "What is your name?". Then, they would state their name, say "Mark", and the voice recognition server would capture that input, translate it to text, store it as a variable, (userName = theResponse;)

Is this possible? Right now I am only seeing options to listen for keywords, which is not desirable for what I am trying to achieve.

Thank you for any and all help.

Upvotes: 3

Views: 2319

Answers (2)

Tyler
Tyler

Reputation: 581

Here's my QuickAction Automator script to open a dialog, start dictation, capture input and run a shell script to convert it to hyphenated text, then it will insert that hyphenated text to the foreground application.

You may need to tweak the keyboard shortcut to start the dictation which is under Preferences->Keyboard->Dictation.

QuickActions will go into the "Services" menu of all applications. You can then assign a keyboard shortcut for that new Service under the Keyboard Preferences. I then make a button on the Accessibility Keyboard to run that shortcut.

on run {input, parameters}

ignoring application responses
    tell application "System Events"
        -- send keystrokes to start dictation.
        -- delay 1
        keystroke "`" using {control down, command down}
    end tell
end ignoring

-- capture input
set theResponse to text returned of (display dialog "Input:" default answer "" with icon note buttons {"Cancel", "Continue"} default button "Continue")

-- convert to hyphenated
set newOutput to do shell script "ruby -e 'puts ARGV.join(\"-\").downcase' " & theResponse


    return newOutput
end run

Upvotes: 1

Tyler Mullins
Tyler Mullins

Reputation: 77

Like Garrett said, What I do is use a dialog to input text. The default voice command key is double pressing the "fn" key.

tell application "Finder"
say "Which application would you like me to open?" using "Alex"
end tell
set theOpen to text returned of (display dialog "Press the 'fn' key twice and speak!" default answer "" buttons {"Cancel", "Ok"} default button 2)
tell application "Finder"
say "Ok! I will open " & theOpen & " for you" using "Alex"
end tell
tell application theOpen
activate
end tell

Upvotes: 1

Related Questions