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;TheMySpeechMgrPresent
function defined in Listing 4-1 uses theGestalt
function to determine whether the Speech Manager is available. TheMySpeechMgrPresent
function tests thegestaltSpeechMgrPresent
bit, and, if the Speech Manager is present, theMySpeechMgrPresent
function speaks the string passed to theSpeakString
function. If theGestalt
function cannot obtain the desired information and returns a result code other thannoErr
, theMySpeechMgrPresent
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. TheSpeakString
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 theSpeakText
orSpeakBuffer
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.