【问题标题】:how to prevent or extend AppleEvent or SpeechRecognitionServer timed out?如何防止或延长 AppleEvent 或 SpeechRecognitionServer 超时?
【发布时间】:2019-03-02 01:40:38
【问题描述】:

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

这是我的代码:

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

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

谢谢!

【问题讨论】:

  • 你可以试试listen continuously for,给它一个标识符来和stop listening for identifier一起使用——这对我来说下载量很大。
  • 你能再解释一下,也许用你的意思的例子。谢谢!
  • 我没有 1.2GB 的下载空间来运行语音识别,但请查看 SpeechRecognitionServer 的脚本字典中的术语。

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


【解决方案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

【讨论】:

  • 您好,感谢您提供此代码!我试过了,当我运行它时,它不到一秒钟就退出了。我一运行它就结束了。
  • 我已将其添加到可以控制我的计算机的应用程序列表中。我已将“连续”添加到我的原始代码并收到此错误:SpeechRecognitionServer 出现错误:{“复制链接”、“粘贴链接”、“给我正在运行的应用程序列表”、“打开文件夹”、“ open chrome"} 无法理解“持续监听”消息。
  • 好的,让我们尝试隔离问题。将我的帖子中的代码原封不动地保存在脚本编辑器应用程序中,作为“保持打开”应用程序。如果不将其保存为“保持打开”应用程序,它将无法工作。通过脚本编辑器应用程序运行代码也不起作用。像运行任何其他应用程序一样运行该应用程序...在 Finder 中双击它。现在应该打开带有自定义命令的听写命令窗口。现在说出其中一些命令,看看它们是否有效。无论您是否启用了增强的听写命令,都应该没有区别。
  • 如果上述步骤有效,请返回脚本编辑器,确保您的保持打开状态的应用程序不再运行,并将我的命令之一替换为您的命令之一。在脚本编辑器中重新保存该文件。再次,在 Finder 中,双击应用程序并再次测试命令
  • 成功了!!!!!!!太感谢了!!!!!非常感谢您花时间帮助我解决这个问题,再次感谢您!
猜你喜欢
  • 2014-07-16
  • 2011-03-20
  • 2015-11-24
  • 2011-04-02
  • 2011-04-22
  • 2011-11-26
  • 2015-08-13
  • 1970-01-01
相关资源
最近更新 更多