Previous Book Contents Book Index Next

Inside Macintosh: Sound /
Chapter 4 - Speech Manager / Using the Speech Manager


Legacy Documentclose button

Important: Inside Macintosh: Sound is deprecated as of Mac OS X v10.5. For new audio development in Mac OS X, use Core Audio. See the Audio page in the ADC Reference Library.

Checking for Speech Manager Capabilities

Because the Speech Manager is not available in all system software versions, you should always check for speech capabilities before attempting to use them. Listing 4-1 defines a function that determines whether the Speech Manager is available.

Listing 4-1 Checking for speech generation capabilities

FUNCTION MySpeechMgrPresent: OSErr;
VAR
   myErr:      OSErr;
   myFeature:  LongInt;                            {feature being tested}
BEGIN
   {Test Speech Manager present bit.}
   myerr := Gestalt(gestaltSpeechAttr, myFeature);
   IF (myErr = noErr) AND (BTst(myFeature, gestaltSpeechMgrPresent)) THEN
   BEGIN
      myErr := SpeakString('The Speech Manager is working and');
      {Wait until synthesizer is done speaking.}
      WHILE (SpeechBusy <> 0) DO
      BEGIN                                        {do nothing}
      END;

      myErr := SpeakString('is almost done.');     
      {Wait until synthesizer is done speaking.}
      WHILE (SpeechBusy <> 0) DO
      BEGIN                                        {do nothing}
      END;
      MySpeechMgrPresent := myErr;
   END;
END;
The MySpeechMgrPresent function defined in Listing 4-1 uses the Gestalt function to determine whether the Speech Manager is available. The MySpeechMgrPresent function tests the gestaltSpeechMgrPresent bit, and, if the Speech Manager is present, the MySpeechMgrPresent function speaks the string passed to the SpeakString function. If the Gestalt function cannot obtain the desired information and returns a result code other than noErr, the MySpeechMgrPresent function assumes that the Speech Manager is not available.

The SpeakString function uses an implied speech channel, that is, the speech channel is automatically created and disposed of by the Speech Manager. The SpeakString function is useful when you need to synthesize Pascal-style strings of fewer than 256 characters. If you need to process text that is longer than 255 characters, then you must allocate a speech channel and use one of the routines that can generate speech in a channel such as the SpeakText or SpeakBuffer function. These routines are much more flexible in that they allow you to speak more text, customize the speech using speech selectors, or alter the generated speech by changing its modulation, pitch, rate, or voice.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
2 JUL 1996