0

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

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

提前致谢!

4

1 回答 1

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
于 2013-07-10T15:08:54.440 回答