Partager via


ISpeechVoiceStatus InputWordLength Property (SAPI 5.3)

Microsoft Speech API 5.3

Interface: ISpeechVoiceStatus

InputWordLength Property

The InputWordLength property retrieves the length of the word currently being spoken by the text-to-speech (TTS) engine.

The InputWordLength property of an ISpeechVoiceStatus object is valid only when its RunningState property is SRSEIsSpeaking.

Syntax

Set: (This property is read-only)
Get: Long = ISpeechVoiceStatus.InputWordLength

Parts

  • ISpeechVoiceStatus
    The owning object.
  • Long
    Set: (This property is read-only)
    Get: A Long variable returning the word length.

Example

The following Visual Basic form code demonstrates the use of the InputWordLength and InputWordPosition properties of an ISpeechVoiceStatus object. 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 creates a voice object and places a sentence in the text box. The Command1_Click procedure speaks the contents of the text box asynchronously and loops until the voice finishes speaking. In this loop, the code uses InputSentencePosition and InputSentenceLength properties to highlight each word in the text box as it is spoken by the TTS engine. A RunningState property of SRSEDone indicates that the voice has finished speaking.

  
Option Explicit

Dim V As SpeechLib.SpVoice

Private Sub Command1_Click()

    Dim ii As Integer
    Dim S As SpeechLib.ISpeechVoiceStatus

    On Error GoTo EH

    V.Speak Text1.Text, SVSFlagsAsync   'Speak the user-editable text

    'Check status periodically
    Do
        For ii = 0 To 5000
            DoEvents
        Next ii

        Set S = V.Status    'Get status in an ISpeechVoiceStatus object

        'Text1.HideSelection must be False for this selection to be seen!

        Text1.SelStart = S.InputWordPosition
        Text1.SelLength = S.InputWordLength

    Loop Until V.Status.RunningState = SRSEDone 'Exit when voice stops

    Text1.SelLength = 0

EH:
    If Err.Number Then ShowErrMsg
End Sub

Private Sub Form_Load()

    On Error GoTo EH
    Set V = New SpVoice
    Text1.Text = "This is a sentence containing several words."

EH:
    If Err.Number Then ShowErrMsg
End Sub

Private Sub ShowErrMsg()

    ' Declare identifiers:
    Dim T As String

    T = "Desc: " & Err.Description & vbNewLine
    T = T & "Err #: " & Err.Number
    MsgBox T, vbExclamation, "Run-Time Error"
    End

End Sub