Garry Pettet
Garry Pettet

Reputation: 8288

AppleScript and Speech

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.

Upvotes: 2

Views: 1245

Answers (2)

caleb531
caleb531

Reputation: 4361

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

Upvotes: 3

regulus6633
regulus6633

Reputation: 19040

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

Upvotes: 1

Related Questions