Name
Speech Listener Application
Dictionary commands
- listen for
listen for is the only command in the Speech Listener application’s dictionary. The Speech Listener app is located in the startup disk:System Folder:Scripting Additions folder. Figure 30-3 shows the Speech Listener icon.
listen for allows a script to
“listen for” any text provided in a
list
of strings (or numbers), then respond
accordingly when it hears one of the listed words or numbers. The
return value of the listen for command is the
text or number that is recognized. The following example first sets a
fam
variable to a list
of
names. It then uses the listen for command to
prompt the user to say one of the names. If the name is recognized
(let’s say it’s
“Emily”) then the computer responds
by saying “Hey guys, Emily is my family member
too!” The [[emph - ]]
syntax is
an embedded speech command that (in this case) de-emphasizes the
pronunciation of the following word. Embedded speech commands are
explained elsewhere in this chapter. If the script listens but does
not hear any spoken commands in 60 seconds, it will time out and
raise error number -1712. The example script catches this error, says
“bye-bye,” and exits the
repeat
loop (effectively terminating the script).
Listen for also raises an error when text is
heard but does not match any of the specified text options.
(* repeat ...
Get AppleScript in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.