Feb 00 Getting Started
Volume Number: 16
Issue Number: 2
Column Tag: Getting Started
Speech Channels
by Dan Parks Sydow
Getting a speech-capable program ready for the use
of different voices
In last month's Getting Started article we started in on the topic of speech in Macintosh
programs. There you saw how your program can verify that the user's Mac is able to
output speech, and you saw how your program can use the SpeakString() function to
speak the text of one string. That was a good start, but if your program is to make good
use of speech there are a couple of other speech-related issues to cover. You'll want
your program to have the ability to speak more than a single string (without having to
repeatedly call SpeakString()). This month we see how that can be done. You'll also
want to give your program the power to speak in different voices. In last month's code
we relied on the default voice - whatever voice is currently set for use on the user's
machine. But the user has a wealth of different voices stored on his or her Mac - and
your program can make use of any one of them! This month we'll see how to make use
of speech channels. An application-allocated speech channel is a prerequisite for
speaking in a different voice - so armed with this new speech channel information
you'll be ready for next month's Getting Started article where we wrap up the topic of
speech by creating an application that speaks in different voices.
Speech Basics Review
It's the Speech Manager - along with a speech synthesizer (that's a part of the Mac
system software), the Sound Manager, and a Mac's audio hardware - that makes speech
possible. If a Mac program is to speak, it should include the Speech.h universal header
file to ensure that the compiler recognizes the speech-related Toolbox functions.
#include
Before attempting to speak, your program should verify that the user's machine will
be able to output the sound (refer to last month's article if you need an explanation of
the following snippet).
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 " );
To speak a single string of text, use the SpeakString() function. Pass this function a
Pascal-formatted string and SpeakString() turns the characters that make up the
string into speech that emits from the user's Mac. Follow a call to SpeakString() with
repeated calls to SpeechBusy() to ensure that time is provided for the full text of the
string to be spoken.