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;TheMySpeechMgrPresentfunction defined in Listing 4-1 uses theGestaltfunction to determine whether the Speech Manager is available. TheMySpeechMgrPresentfunction tests thegestaltSpeechMgrPresentbit, and, if the Speech Manager is present, theMySpeechMgrPresentfunction speaks the string passed to theSpeakStringfunction. If theGestaltfunction cannot obtain the desired information and returns a result code other thannoErr, theMySpeechMgrPresentfunction assumes that the Speech Manager is not available.The
SpeakStringfunction uses an implied speech channel, that is, the speech channel is automatically created and disposed of by the Speech Manager. TheSpeakStringfunction 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 theSpeakTextorSpeakBufferfunction. 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.