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.
SpeakBuffer
You can use the SpeakBuffer function to have the Speech Manager speak a buffer of text, using certain flags to control speech behavior.
FUNCTION SpeakBuffer (chan: SpeechChannel; textBuf: Ptr; textBytes: LongInt; controlFlags: LongInt): OSErr;
chan- The speech channel through which speech is to be spoken.
textBuf- A pointer to the first byte of text to spoken.
textBytes- The number of bytes of text to spoken.
controlFlags- Control flags to customize speech behavior.
DESCRIPTION
TheSpeakBufferfunction behaves identically to theSpeakTextfunction, but allows control of several speech parameters by setting values of thecontrolFlagsparameter. ThecontrolFlagsparameter relies on the following constants, which may be applied additively:
CONST kNoEndingProsody = 1; {disable prosody at end of sentences} kNoSpeechInterrupt = 2; {do not interrupt current speech} kPreflightThenPause = 4; {compute speech without generating}Each constant specifies a flag bit of thecontrolFlagsparameter, so by passing the constants additively you can enable multiple capabilities ofSpeakBuffer. If you pass 0 in thecontrolFlagsparameter,SpeakBufferworks just likeSpeakText. By passingkNoEndingProsody + kNoSpeechInterruptin thecontrolFlagsparameter,SpeakBufferworks likeSpeakTextexcept that thekNoEndingProsodyandkNoSpeechInterruptfeatures have been selected. Future versions of the Speech Manager may define additional constants.The
kNoEndingProsodyflag bit is used to control whether or not the speech synthesizer automatically applies ending prosody, the speech tone and cadence that normally occur at the end of a statement. Under normal circumstances (for example, when the flag bit is not set), ending prosody is applied to the speech when the end of thetextBufdata is reached. This default behavior can be disabled by setting thekNoEndingProsodyflag bit.Some synthesizers do not speak until the
kNoEndingProsodyflag bit is reset, or they encounter a period in the text, ortextBufis full.The
kNoSpeechInterruptflag bit is used to control the behavior ofSpeakBufferwhen called on a speech channel that is still busy. When the flag bit is not set,SpeakBufferbehaves similarly toSpeakStringandSpeakText. Any speech currently being produced on the specified speech channel is immediately interrupted, and then the new text buffer is spoken. When thekNoSpeechInterruptflag bit is set, however, a request to speak on a channel that is still busy processing a prior text buffer will result in an error. The new buffer is ignored and the errorsynthNotReadyis returned. If the prior text buffer has been fully processed, the new buffer is spoken normally. One way of achieving continuous speech without using callback procedures is to continually callSpeakBufferwith thekNoSpeechInterruptflag bit set until the function returnsnoErr. The function will then execute as soon as the first text buffer has been processed.The
kPreflightThenPauseflag bit is used to minimize the latency experienced when the speech synthesizer is attempting to speak. Ordinarily, whenever a call toSpeakString,SpeakText, orSpeakBufferis made, the speech synthesizer must perform a certain amount of initial processing before speech output is heard. This startup latency can vary from a few milliseconds to several seconds depending upon which speech synthesizer is being used. Recognizing that larger startup delays might be detrimental to certain applications, a mechanism exists to allow the synthesizer to perform any necessary computations at noncritical times. Once the computations have been completed, the speech is able to start instantly. When thekPreflightThenPauseflag bit is set, the speech synthesizer will process the input text as necessary to the point where it is ready to begin producing speech output. At this point, the synthesizer will enter a paused state and return to the caller. When the application is ready to produce speech, it should call theContinueSpeechfunction to begin speaking.When the
controlFlagsparameter is set to 0,SpeakBufferbehaves identically toSpeakText.SPECIAL CONSIDERATIONS
Because theSpeakBufferfunction might move memory, you should not call it at interrupt time.ASSEMBLY-LANGUAGE INFORMATION
The trap macro and routine selector for theSpeakBufferfunction are
Trap macro Selector _SoundDispatch$0828000C RESULT CODES
noErr 0 No error synthNotReady -242 Speech channel is still busy speaking invalidComponentID -3000 Speech channel is uninitialized or bad