如何防止或延长AppleEvent或SpeechRecognitionServer超时?

时间:2019-03-02 01:40:38

标签: applescript runtime-error speech-recognition applescript-objc appleevents

我正在研究SpeechRecognition项目,并且我已经完成了很多工作。但是,有一件事我无法弄清楚。当我启动我的应用程序时,它会监听我的命令,如果我坚持或不讲这些命令,那么它将给我这个脚本错误: enter image description here 超时了。我希望它保持24小时开放,即使我什么也没说。

这是我的代码:

tell application "SpeechRecognitionServer"
    with timeout of 10000 seconds
        set FRIDAY_AI to listen for commands
    end timeout
end tell

如果您能帮助我解决这个问题,我将不胜感激。

谢谢!

1 个答案:

答案 0 :(得分:1)

我在计算机上执行的所有操作中,大约70%由听写命令和我自己的自定义听写命令控制。一旦掌握了功能,它就会非常强大。我为您设置了一个带有一些示例的小脚本,以使SpeechRecognitionServer应用程序不断侦听要执行的一组口头命令。我认为通过查看代码使其能够根据您的需求进行调整是不言自明的。

在“脚本编辑器”中,将以下代码另存为保持打开状态的应用程序。确保将“系统偏好设置”中的新应用添加到允许控制计算机的应用列表中。现在,您需要做的就是启动新应用。

on idle
    try
        tell application "SpeechRecognitionServer"
            set theChoice to listen continuously for ¬
                {"Open Google", "Close Windows", "Enter Name", "Enter Password", "Close My Commands"} ¬
                    with identifier "mine" with section title "WeeeHaaa's Commands"

            if theChoice is "Open Google" then
                tell application "Google Chrome" to activate
            else if theChoice is "Close Windows" then
                tell application "Finder" to close windows
            else if theChoice is "Enter Name" then
                set myFullname to "Crazy Eddie"
                tell application "System Events"
                    keystroke myFullname
                end tell
            else if theChoice is "Enter Password" then
                set myPassword to "secretpassword"
                tell application "System Events"
                    keystroke myPassword
                end tell
            else if theChoice is "Close My Commands" then
                quit me
            end if

        end tell
    end try
    return 0.5
end idle

on quit
    -- stop listening
    tell application "SpeechRecognitionServer"
        stop listening for identifier "mine"
    end tell
    continue quit
end quit

enter image description here

enter image description here

相关问题