AppleScript 和语音

发布于 2024-10-17 08:50:41 字数 93 浏览 11 评论 0原文

是否可以使用 AppleScript 停止 Mac 当前正在生成(或已排队)的任何语音?

我基本上是在寻找与AppleScript“say”命令相反的命令。

Is it possible to stop any speech that the Mac is currently producing (or has queued) using an AppleScript?

I'm basically looking for the opposite of the AppleScript "say" command.

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

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

发布评论

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

评论(2

诠释孤独 2024-10-24 08:50:41

试试这个,一个完整的 AppleScript 解决方案(不需要 shell):

-- say some text asynchronously
say "Hello, world!" waiting until completion no
-- delay 1 second before stopping
delay 1
-- stop text by saying nothing, which stops current speech
say "" with stopping current speech

Try this, a complete AppleScript solution (no shell required):

-- say some text asynchronously
say "Hello, world!" waiting until completion no
-- delay 1 second before stopping
delay 1
-- stop text by saying nothing, which stops current speech
say "" with stopping current speech
乱了心跳 2024-10-24 08:50:41

要停止演讲,您必须停止运行演讲的进程。当您说“Mac 当前正在生成的任何语音”时,这很难做到,因为可能有不同的进程生成语音。你必须找到一种方法来确定演讲的内容。

这是一个我生成语音的示例,因此我知道要终止哪个进程才能使语音停止。

set theText to "Is it possible to stop any speech that the Mac is currently producing (or has queued) using an AppleScript? I'm basically looking for the opposite of the AppleScript \"say\" command."
set thePID to do shell script "say " & quoted form of theText & " > /dev/null 2>&1 & echo $!"

delay 1
do shell script "kill " & thePID

To stop the speech you would have to stop the process running the speech. That's difficult to do when you say "any speech that the Mac is currently producing" because there could be different processes producing the speech. You'd have to figure out a way to determine what is producing the speech.

Here's an example where I generate the speech thus I know what process to kill to make the speech stop.

set theText to "Is it possible to stop any speech that the Mac is currently producing (or has queued) using an AppleScript? I'm basically looking for the opposite of the AppleScript \"say\" command."
set thePID to do shell script "say " & quoted form of theText & " > /dev/null 2>&1 & echo $!"

delay 1
do shell script "kill " & thePID
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文