DekGenius.com
Team LiB   Previous Section   Next Section
SpeakableItems Extension

You can make your scripts executable by spoken command as long as you have the SpeakableItems extension file loaded on your machine, and you have turned SpeakableItems on in the Speech control panel (see Figure 30-1). This speech technique is as simple as this: create a script that does whatever you want then give it a filename that you will use to verbally execute the script. For instance, you can save the script as an applet with the filename go. As long as the script has been saved in the startup disk:System Folder:Apple Menu Items:SpeakableItems folder and SpeakableItems is turned on, all the user has to do is say "go" into the computer's microphone and the script is executed. The following example uses a web browser to open up the my.yahoo.com page upon spoken command, which in this case is "go to yahoo" (i.e., the filename of the script must be go to yahoo, and the script must be saved to the SpeakableItems folder):

tell application "Internet Explorer"
   Activate
   GetURL "http://my.yahoo.com"
end tell

say scripting addition

The say command is an osax that you can use to have the computer speak text to the script user. It is extremely easy to use; simply follow the keyword say with the string text that you want the computer to say. This command requires the Speech Manager extension (see Figure 30-2), which enables the computer to read text to the user. You can use the say command alongside other speech technologies, such as the Speech Listener application. The following example tells the user what time it is. It gets the current time from the current date scripting addition. The time string property returns just the time portion of the date, as in "10:52:26 AM." Appendix A also describes the say command. A description of say and its parameters follows this example. The example also uses embedded speech commands (which are explained at the end of this chapter):

set t to (time string of (current date)) (* returns something like 
"11:17:00 AM" *)
set t1 to "" (* t1 var will hold just the time part as in "11:17:00", 
without the "AM" *)
set t2 to ((characters -1 thru -2 of t) as text) -- holds "AM" or "PM"
set t3 to "" -- will hold the lower case "am" or "pm"
(* remove the " AM" part of "11:17:00 AM," for instance, and store the 
result in a variable *)
repeat with chr from 1 to (t's length)
   if (character chr of t) is space then exit repeat
   set t1 to t1 & (character chr of t)
end repeat
(* create a lower case version of "AM" or "PM" so that the speech 
software reads the time of day as "ay-em" or "pee-em" using the [[ char 
LTRL ]] embedded speech command *)
repeat with chr from 1 to 2
   set n to (ASCII number (t2's character chr)) + 32 (* converts from 
upper to lower case using ASCII number osax *)
   set t3 to t3 & (ASCII character n) -- uses ASCII character osax
end repeat
say "It is [[ emph - ]] [[ slnc 500 ]]" & t1 & " [[ char LTRL ]]" & t3
say anything

This command speaks the text parameter to the say osax in the voice that is configured in the Speech control panel. You can use this command for debugging purposes by saying the value of certain variables.

displaying string

This parameter displays text in the SpeakableItems feedback window, if you have the SpeakableItems extension installed.

using string

You can specify the voice you want to use, such as "Deranged" or "Hysterical":

say "This project is disintegrating!" using "Hysterical"
waiting until completion boolean

The default is waiting until completion true, which does not return from the call to say until the speech has been uttered. This is important when you are using say in a repeat loop, as you do not want to move on to the next loop of repeat until the speaking voice has finished its speech. Chapter 7 describes the repeat loop.

    Team LiB   Previous Section   Next Section