Apple脚本听取是或否答案

时间:2013-07-10 14:35:48

标签: automation applescript voice-recognition

我实际上有这个脚本工作,(我是一个完全初学者的惊喜)但我只是想确保这个脚本没有任何我不需要的多余代码。或者,如果有更好的方法,请评论!我最终试图创建一系列语音命令。

tell application "SpeechRecognitionServer"
set l1 to {"yes", "sure", "yes please", "open mail"}
set l2 to {"no", "no thanks", "not now"}
set no_answer to {"no", "no thanks", "not now"}

set answer to listen for l1 & l2 with prompt "Would you like me to open your email"
l1 contains answer
l2 contains no_answer


end tell

if l1 contains answer then
say "yes answer"

else if l2 contains no_answer then
say "no answer"
end if

end

提前致谢!

1 个答案:

答案 0 :(得分:0)

您应该只在tell块中包含属于您“告诉”的应用程序的命令。在块外构建列表。

set l1 to {"yes", "sure", "yes please", "open mail"}
set l2 to {"no", "no thanks", "not now"}

这没有做任何事情。

l1 contains answer
l2 contains no_answer

l2将始终包含no_answer,因为它们是两个静态列表。

else if l2 contains no_answer

尝试这样的事情:

set l1 to {"yes", "sure", "yes please", "open mail"}
set l2 to {"no", "no thanks", "not now"}

activate application "SpeechRecognitionServer"

try
    tell application "SpeechRecognitionServer" to set answer to listen for l1 & l2 with prompt "Would you like me to open your email" giving up after 20
on error number -128
    say "User did not respond"
    error number -128
end try

if l1 contains answer then
    say "yes answer"

else if l2 contains answer then
    say "no answer"
end if