Macos 语音识别服务器未保持打开状态

Macos 语音识别服务器未保持打开状态,macos,applescript,speech-recognition,Macos,Applescript,Speech Recognition,我试图创建一个简单的程序,使用com.apple.speech.recognitionserver循环用户语音输入。到目前为止,我的代码如下: set user_response to "start" repeat while user_response is not equal to "Exit" tell application id "com.apple.speech.recognitionserver" set user_response to listen for {"Tim

我试图创建一个简单的程序,使用com.apple.speech.recognitionserver循环用户语音输入。到目前为止,我的代码如下:

set user_response to "start"

repeat while user_response is not equal to "Exit"
tell application id "com.apple.speech.recognitionserver"
    set user_response to listen for {"Time", "Weather", "Exit"} with prompt
            "Good Morning"
end tell


if user_response = "Time" then
    set curr_time to time string of (the current date)
    set curr_day to weekday of (the current date)
    say "It is"
    say curr_time
    say "on"
    say curr_day
    say "day"

else if user_response = "Weather" then
    say "It is hot outside. What do you expect?"
end if
end repeat

say "Have a good day"

如果在我的系统上运行上述命令,它会说早上好,然后会弹出语音输入系统,等待时间、天气或退出。他们都会按照自己说的去做,但如果我说时间和天气,他们不会循环,然后再问,直到我说退出,speechserver超时,再也不会弹出。有没有办法让应用程序一直打开到程序结束,或者applescript无法循环用户语音输入?

如果找不到办法让语音识别保持打开,请在再次调用之前尝试添加延迟。我记得(很久以前)发现如果尝试将事件发送到已经退出的应用程序(它不重启应用程序),则事件可能会丢失。

在结束之前重复添加

告诉应用程序“SpeechRecognitionServer” 退出 结束语

大约35秒后,它会重复,在寒冷的日子里,它会像蜂蜜一样慢,但它会起作用。试试看

下面是一个简单的例子:

repeat
    tell application "SpeechRecognitionServer"
        set theResponse to listen for {"yes", "no"} with prompt "open a finder?"
        set voice to (theResponse as text)
    end tell
    if voice contains "yes" then
        tell application "Finder"
            activate
        end tell
    else
        say "not understood"
    end if
    tell application "SpeechRecognitionServer"
        quit
    end tell
end repeat

在第一次重复和讲述之间大约延迟5秒,效果很好。非常感谢。