开发者

AppleScript and Speech

开发者 https://www.devze.com 2023-02-10 11:10 出处:网络
Is it possible to sto开发者_JAVA百科p any speech that the Mac is currently producing (or has queued) using an AppleScript?

Is it possible to sto开发者_JAVA百科p 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.


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


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
0

精彩评论

暂无评论...
验证码 换一张
取 消