语音识别服务器不会保持打开状态

时间:2010-05-07 19:31:18

标签: 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 {"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"

如果以上内容在我的系统上运行,它会说早上好,然后弹出语音输入系统并等待时间,天气或退出。他们都按照他们所说的去做,但如果我说“时间和天气”并再次询问,直到我说退出语音服务器超时并且再也不会弹出,而不是循环。有没有办法在程序结束之前保持该应用程序打开,或者是否无法循环用户语音输入?

2 个答案:

答案 0 :(得分:1)

如果您没有找到保持语音识别功能打开的方法,请在再次调用之前尝试添加延迟。我记得(很久以前)发现如果你试图将事件发送到已经处于退出状态的应用程序(它不会重新打开应用程序),事件就会丢失。

答案 1 :(得分:0)

在结束之前重复添加

告诉应用程序“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