GMind
GMind

Reputation: 31

how can you integrate speech recognition into apple script and understand key words and more than a few word

This is a example of a simple code I'm using for my virtual assistant:

tell application "SpeechRecognitionServer"
    set theResponse to listen for {"good", "bad"} with prompt "How are you?"
    if theResponse is "good" then
        say "Wonderful sir… Is there anything you want me to do for you?"
    else
        say "Cheer up chap! Is there anything you want me to do for you?"
    end if
end tell

Can anyone develop this even more, so it can understand more than 2 words and understand certain keywords?

Upvotes: 3

Views: 3134

Answers (1)

Isaiah
Isaiah

Reputation: 1902

You could, I assume, use two lists, one that stands for "Good", and another that stands for "Bad":

set good_list to {"Good", "Fine", "I'm fine", "OK", "Okay"} --List of words, meaning "Good"
set bad_list to {"Bad", "Irritated", "Fustrated", "Depressed"} --List of words, meaning "Bad"
set complete_list to good_list & bad_list

tell application "SpeechRecognitionServer"
    set theResponse to listen for complete_list with prompt "How are you?"
    if (good_list contains theResponse) then
        say "Wonderful sir… Is there anything you want me to do?"
    else if (bad_list contains theResponse) then
        say "Clear up, chap! Is there anything you want me to do?"
    end if
end tell

Remember, the more words or group words you include in the list, the more your script can understand!

If you want to, you could make it look more intelligent, by using the spoken answer (of the user), in the sentence the computer would say. It would look like this:

set good_list to {"Good", "Fine", "I'm fine", "OK", "Okay"} --List of words, meaning "Good"
set bad_list to {"Bad", "Irritated", "Fustrated", "Depressed"} --List of words, meaning "Bad"
set complete_list to good_list & bad_list

tell application "SpeechRecognitionServer"
    set theResponse to listen for complete_list with prompt "How are you?"
    if (good_list contains theResponse) then
        if theResponse = "I'm fine" then
            set theResponse to "Fine" --Otherwise you would get a very weird sentence
        end if
        say theResponse & " is good sir! Is there anything you want me to do?"
    else if (bad_list contains theResponse) then
        if theResponse = "Bad" then
            set theResponse to "feeling bad" --Otherwise you would get a very weird sentence
        end if
        say "Oh, are you " & theResponse & "? Well, clear up chap! Is there anything you want me to do?"
    end if
end tell

Sorry, but I just had to correct your text mistakes (:

Upvotes: 3

Related Questions