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.
Adjusting Speech Attributes
Speech attributes are settings defined for a class of voices or for all voices that affect the quality of speech produced by the Speech Manager. In general, an application should not try to second-guess the developers of a voice or synthesizer by arbitrarily setting a speech attribute. However, there are some cases in which you would want to adjust the rate of speech (how many words per minute are spoken) or the speech pitch (the listener's subjective interpretation of speech's average frequency). Listing 4-4 shows how to adjust the speech pitch and speech rate of a particular channel.Listing 4-4 Changing the speech rate and pitch
FUNCTION MyAdjustSpeechAttributes: OSErr; VAR myErr: OSErr; myErr2: OSErr; myPitch: Fixed; myRate: Fixed; myStr: Str255; BEGIN myStr := 'This is the old pitch and rate.'; myErr := NewSpeechChannel(NIL, gChannel); {allocate a channel} IF myErr = noErr THEN BEGIN {speak a string} myErr := SpeakText(gChannel, @myStr[1], Length(myStr)); WHILE (SpeechBusy <> 0) DO {wait for speech to finish} BEGIN END; {Find the current speech pitch.} myErr := GetSpeechPitch(gChannel, @myPitch); myPitch := myPitch * 2; {double the pitch} IF myErr = noErr THEN myErr := SetSpeechPitch(gChannel, myPitch); {change the pitch} {Find the current speech rate.} IF myErr = noErr THEN myErr := GetSpeechRate(gChannel, @myRate); myRate := myRate * 2; {double the rate} IF myErr = noErr THEN myErr := SetSpeechRate(gChannel, myRate); {change the rate} {Speak a string with new attributes.} myStr := 'This is the new pitch and rate.'; myErr := SpeakText(gChannel, @myStr[1], Length(myStr)); WHILE (SpeechBusy <> 0) DO {wait for speech to finish} BEGIN END; {Dispose of the speech channel.} IF gChannel <> NIL THEN myErr2 := DisposeSpeechChannel(gChannel); END; IF myErr = noErr THEN MyAdjustSpeechAttributes := myErr2 ELSE MyAdjustSpeechAttributes := myErr; END;TheMyAdjustSpeechAttributes
function first allocates a speech channel, as demonstrated previously. Then the MyAdjustSpeechAttributes function speaks a string to demonstrate the default speech rate and pitch for the default system voice. After the speech synthesis is finished, MyAdjustSpeechAttributes calls theGetSpeechPitch
function with a valid speech channel and a pointer to a fixed-point value in which the value of the current speech pitch is returned. Then MyAdjustSpeechAttributes doubles the value of the speech pitch by multiplying and passes the new value to theSetSpeechPitch
function.MyAdjustSpeechAttributes repeats this sequence to determine the speech rate using the
GetSpeechRate
function, doubles the rate, and sets a new speech rate by passing the new rate value to theSetSpeechRate
function. Next, MyAdjustSpeechAttributes callsSpeakText
again to demonstrate the new speech pitch and rate. Creating a loop with theSpeechBusy
function allows the synthesizer to finish speaking its text, and then MyAdjustSpeechAttributes disposes of the active channel.When you set a rate value, each synthesizer may or may not be able to support that exact value. A synthesizer will attempt to set the value you specify, but it may substitute a value that it can support that is the closest it can come to your value. Don't be alarmed if
GetSpeechRate
returns a value other than the one you thought you set. The value returned is the closest value to the one set that the synthesizer is capable of reproducing.