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

发布于 2024-08-31 22:00:32 字数 868 浏览 8 评论 0原文

我正在尝试创建一个简单的程序,使用 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"

如果上面的代码在我的系统上运行,它会说早上好,然后弹出语音输入系统并等待时间、天气或退出。他们都按照他们说的去做,但是如果我说时间和天气,他们不会循环并再次询问,直到我说退出,语音服务器超时并且永远不会再次弹出。有没有办法让该应用程序保持打开状态直到程序结束,或者 applescript 无法循环用户语音输入?

I am trying to create a simple program that loops for user speech input using com.apple.speech.recognitionserver. My code thus far is as follows:

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"

If the above is run on my system it says good morning and it then pops up with the speech input system and waits for either Time, Weather, or Exit. They all do what they say they are going to do, but instead of looping if I say Time and Weather and asking again until I say exit the speechserver times out and never pops up again. Is there a way of either keeping that application open until the program ends or is applescript not capable of looping for user speech input?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

血之狂魔 2024-09-07 22:00:33

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

If you don't find a way to keep speech recognition open, try adding a delay before you call it again. I recall (long ago) finding that events can be just lost if you try to send an event to an application that's already in the middle of quitting (it doesn't reopen the application).

⊕婉儿 2024-09-07 22:00:33

在结束之前重复添加

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

Before your end Repeat add

tell application "SpeechRecognitionServer"
quit
end tell

After about 35 seconds it will repeat, it is slow as honey on a cold day but it works. give it a try.

Here is a Simple Example:

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文