SpVoice StartStream event (Microsoft Speech Platform)

Microsoft Speech Platform SDK 11

Microsoft Speech Platform

Object: SpVoice (Events)

StartStream Event

The StartStream event occurs when the text-to-speech (TTS) engine begins speaking a stream for the SpVoice object.

The StartStream and EndStream events can be used together to determine the duration of a stream being spoken.


SpVoice.StartStream(
     StreamNumber As Long,
     StreamPosition As Variant
)

Parameters

StreamNumber
The stream number which generated the event. When a voice enqueues more than one stream by speaking asynchronously, the stream number is necessary to associate an event with the appropriate stream.
StreamPosition
The character position in the output stream at which the stream begins.

Example

The following Visual Basic form code demonstrates the use of the StartStream and EndStream events. To run this code, create a form with the following controls:

  • A command button called Command1
  • A text box called Text1

Paste this code into the Declarations section of the form.

The Form_Load procedure puts a text string in Text1 and creates a voice object. The command1_Click procedure calls the Speak method. This will cause the TTS engine to send the StartStream and EndStream events to the voice. The StartStream event code changes the color of the text in the text box to red; the EndStream event changes the color back to black.

The text color change in this example has no significance other than showing the duration of the text stream.


Option Explicit

Public WithEvents vox As SpeechLib.SpVoice

Private Sub Command1_Click()
    vox.Speak Text1.Text, SVSFlagsAsync
End Sub

Private Sub Form_Load()
    Set vox = New SpVoice
    Text1.Text = "This text turns red while being spoken."
End Sub

Private Sub vox_EndStream(ByVal StreamNumber As Long, ByVal StreamPosition As Variant)
    Text1.ForeColor = vbBlack
End Sub

Private Sub vox_StartStream(ByVal StreamNumber As Long, ByVal StreamPosition As Variant)
    Text1.ForeColor = vbRed
End Sub