语音识别服务器未保持打开状态
我正在尝试创建一个简单的程序,使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您找不到保持语音识别打开的方法,请尝试在再次调用之前添加延迟。我记得(很久以前)发现如果您尝试将事件发送到已经处于退出状态的应用程序(它不会重新打开应用程序),则事件可能会丢失。
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).
在结束之前重复添加
告诉应用程序“SpeechRecognitionServer”
辞职
结束告诉
大约 35 秒后,它会重复,虽然在寒冷的日子里像蜂蜜一样缓慢,但它有效。尝试一下。
这是一个简单的例子:
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: