applescript - 您如何将语音识别集成到苹果脚本中并理解关键词和多个单词

标签 applescript voice-recognition

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

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

任何人都可以进一步开发它,使其能够理解超过 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

抱歉,我不得不更正您的文字错误 (:

关于applescript - 您如何将语音识别集成到苹果脚本中并理解关键词和多个单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16389813/

相关文章:

macos - JavaScript 中的 Application.make 用于自动化 (JXA)

tensorflow - 语音识别(使用ML?),而不是语音识别

voice-recognition - Dragon Naturally speak Premium 可以用于编程吗?

cocoa - 确定应用程序是否是从 AppleScript 启动的

applescript - 有没有办法用 applescript 读取 Quicktime 电影的时间码轨道

terminal - 如何从终端和 AppleScript 在模拟器中启动 iOS 应用程序

python - 当语音识别结果不是预期时打印消息

android - 语音计算器的离线语音识别

android - SpeechRecognizer 未启动

macos - 为什么我的 Applescript 打开多个终端窗口?