1

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

这是我的代码:

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

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

谢谢!

4

1 回答 1

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

在此处输入图像描述

在此处输入图像描述

于 2019-03-02T05:44:44.040 回答