SpVoice Word event (SAPI 5.3)

Microsoft Speech API 5.3

Object: SpVoice (Events)

Word Event

The Word event occurs when the text-to-speech (TTS) engine detects a word boundary while speaking a stream for the SpVoice object.

  
    SpVoice.Word(
     StreamNumber As Long,
     StreamPosition As Variant,
     CharacterPosition As Long,
     Length As Long
)

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 word begins.
  • CharacterPosition
    The character position in the input stream one character before the start of the word. In the case of the first word in a stream, this parameter is zero.
  • Length
    The length of the word in the input stream.

Example

The following Visual Basic form code demonstrates the use of the Word event. To run this code, create a form with the following controls:

  • A command button called Command1
  • A text box called Text1
  • Set the HideSelection property of Text1 to False

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 Word event to the voice; the Word event code will use the event parameters to highlight the word associated with the event.

  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 is some text in a textbox."

End Sub

Private Sub vox_Word(ByVal StreamNumber As Long, ByVal StreamPosition As Variant, _
                     ByVal CharacterPosition As Long, ByVal Length As Long)

    ' In order to show this selection,
    ' the Text1.HideSelection property must be False!

    Text1.SelStart = CharacterPosition
    Text1.SelLength = Length

End Sub