Mar 00 Getting Started
Volume Number: 16
Issue Number: 3
Column Tag: Getting Started
Speech and Voices
by Dan Parks Sydow
Writing a Macintosh program that makes use of
different voices
Two months ago, Getting Started introduced the topic of adding computer-generated
speech to a Mac program. In that article you learned how to verify that the user's Mac
is able to output speech and then use the Toolbox SpeakString() function to speak the
text of one string. Last month's Getting Started article carried on with the topic of
speech by demonstrating how a program can create a speech channel in order to speak
more than a single string. This month we complete the trilogy of speech articles by
seeing how a speech channel is used by a program that wants to alter the voice that's
used in the generation of speech.
Speech Basics Review
A Mac program that is to speak should include the Speech.h universal header file to
make sure that the compiler recognizes the speech-related Toolbox functions. The
program should also verify that the user's Mac is able to generate speech. After that, a
string of text can be spoken by calling the Toolbox function SpeakString(). A
Pascal-formatted string is the only argument. After that, repeatedly call the Toolbox
function SpeechBusy() to allow for the Mac to complete talking. If the following
snippet doesn't look familiar, refer back to the January Getting Started article for
more information.
OSErr err;
long response;
long mask;
err = Gestalt( gestaltSpeechAttr, &response );
if ( err != noErr )
DoError( "\pError calling Gestalt" );
mask = 1 << gestaltSpeechMgrPresent;
[TOKEN:26982] ( response & mask == 0 )
DoError( "\pSpeech Manager not present " );
err = SpeakString( "\pThis is a test." );
if ( err != noErr )
DoError( "\pError attempting to speak a phrase" );
while ( SpeechBusy() == true )
;
Speech Channels Review
Last month's Getting Started introduced speech channels. In order to specify which
voice to use, you're program needs to allocate such a channel - so take a quick look at
some of the code from last month.
A speech channel is a data structure that holds descriptive information about the voice
that is to be used to speak. If you're program needs to alternate voices, you may want to
create two or more speech channels - one for each voice. The Toolbox function
NewSpeechChannel() creates a new speech channel record and returns a
SpeechChannel - a pointer to that record.
SpeechChannel channel;
OSErr err;
err = NewSpeechChannel( nil, &channel );
The first NewSpeechChannel() argument is a pointer to a voice specification data
structure. Passing a value of nil as the first argument results in assigning the system
default voice as the voice to be used by speech that comes eventually comes from this
new channel.
Voices
To this point we've relied on the default voice - the voice the user's Mac uses when a
program doesn't specify a particular voice. As shown in Figure 1, the_user uses the
Speech control panel to determine which voice is to be the default voice.
Figure 1.The Speech control panel.
As shown on the left of Figure 2, the Speech control panel includes a pop-up menu that
lets the user choose a voice. And as shown on the right of Figure 2, each voice in the
Speech control panel pop-up menu corresponds to a voice in the System Folder of the
user's Mac (in the Voices folder in the Extensions folder, to be exact).
Figure 2.Each voice in the Speech control panel pop-up menu corresponds to a
system voice file
As shown in Figure 2, voices each have a name. So it might seem logical that your