3

这是我用于虚拟助手的简单代码示例:

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

任何人都可以进一步开发它,使其可以理解两个以上的单词并理解某些关键字吗?

4

1 回答 1

2

我假设您可以使用两个列表,一个代表“好”,另一个代表“坏”:

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

请记住,列表中包含的单词或组词越多,您的脚本就越能理解!

如果你愿意,你可以让它看起来更智能,通过使用(用户的)口头回答,在计算机会说的句子中。它看起来像这样:

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

抱歉,我只需要更正您的文字错误(:

于 2013-05-08T15:07:36.317 回答