ISpeechVoiceStatus CurrentStreamNumber Property (SAPI 5.3)
Microsoft Speech API 5.3
The CurrentStreamNumber property retrieves the number of the text input stream being spoken by the text-to-speech (TTS) engine.
The CurrentStreamNumber property of an ISpeechVoiceStatus object is valid only when its RunningState property is SRSEIsSpeaking.
|Set:||(This property is read-only)|
|Get:||Long = ISpeechVoiceStatus.CurrentStreamNumber|
The owning object.
Set: (This property is read-only)
Get: A Long variable that returns the stream number.
The following Visual Basic form code demonstrates the use of the CurrentStreamNumber and RunningState properties. To run this code, create a form with the following controls:
- A command button called Command1
- A list box called List1
Paste this code into the Declarations section of the form.
The Form_Load procedure creates a voice. The Command1_Click procedure speaks three text streams asynchronously, putting each in the list box, and then performs a loop until the voice finishes speaking. Inside this loop, the code uses the CurrentStreamNumber property to highlight each line of text in the list box while it is spoken by the TTS engine. A RunningState property of SRSEDone indicates that the voice has finished speaking.
Option Explicit Private V As SpeechLib.SpVoice Private Sub Command1_Click() Dim ii As Integer On Error GoTo EH List1.Clear 'Place text strings in the List box, and speak them List1.AddItem "This is stream number one." V.Speak "This is stream number one.", SVSFlagsAsync List1.AddItem "A second stream, now." V.Speak "A second stream, now.", SVSFlagsAsync List1.AddItem "The third stream is next." V.Speak "The third stream is next.", SVSFlagsAsync 'Check status periodically Do For ii = 0 To 1000 DoEvents Next ii 'Highlight the stream being spoken List1.ListIndex = V.Status.CurrentStreamNumber - 1 Loop Until V.Status.RunningState = SRSEDone 'Exit when voice stops List1.ListIndex = -1 'Turn highlight off EH: If Err.Number Then ShowErrMsg End Sub Private Sub Form_Load() On Error GoTo EH Set V = New SpVoice 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