AppleScript and Speech
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
精彩评论