ISpeechVoiceStatus RunningState Property (SAPI 5.4)
Microsoft Speech API 5.4
The RunningState property retrieves the run state of the voice, which indicates whether the voice is speaking or inactive.
The values of the RunningState property are contained in the SpeechRunState enumeration.
|Set:||(This property is read-only)|
|Get:||SpeechRunState = ISpeechVoiceStatus.RunningState|
The owning object.
Set: (This property is read-only)
Get: A SpeechRunState constant returning the run state of the voice.
The following Visual Basic form code demonstrates the use of the RunningState property 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
- A timer called Timer1
Paste this code into the Declarations section of the form.
The Form_Load procedure places a sentence in the text box and creates two voice objects, one with an alert Priority setting. In the Command1_Click procedure, the timer is activated, and the normal Priority voice enqueues the contents of the text box, and waits a tenth of a second. Then the alert Priority voice speaks a short stream which interrupts the normal voice.
The timer procedure changes the color of the text box depending on the run state of the normal voice. When the normal voice is speaking, the text color is red; when it is done speaking, the text color is blue; when the voice is not speaking, the text color is black.
The text color change in this example has no significance other than indicating the running state of the normal voice.
Option Explicit Private V As SpeechLib.SpVoice Private VHim As SpeechLib.SpVoice Private Sub Command1_Click() On Error GoTo EH Timer1.Interval = 250 Timer1.Enabled = True 'Make sure normal voice starts first V.Speak Text1.Text, SVSFlagsAsync V.WaitUntilDone (100) VHim.Speak "Alert voice!", SVSFlagsAsync EH: If Err.Number Then ShowErrMsg End Sub Private Sub Form_Load() On Error GoTo EH Set V = New SpVoice Text1.Text = "turn this text red while the voice is speaking it" Set V.Voice = V.GetVoices("Gender=Female").Item(0) Set VHim = New SpVoice VHim.Priority = SVPAlert Set VHim.Voice = VHim.GetVoices("Gender=Male").Item(0) EH: If Err.Number Then ShowErrMsg End Sub Private Sub Timer1_Timer() On Error GoTo EH Select Case V.Status.RunningState Case SRSEIsSpeaking Text1.ForeColor = vbRed Case SRSEDone Text1.ForeColor = vbBlue Case Else Text1.ForeColor = vbBlack End Select 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