Share via


SpeechRecoContext RecognizerStateChange Event (SAPI 5.3)

Microsoft Speech API 5.3

Interface: ISpeechRecoContext Events

RecognizerStateChange Event

The RecognizerStateChange event occurs when the SR engine changes state.

  
    SpeechRecoContext.RecognizerStateChange(
     StreamNumber As Long,
     StreamPosition As Variant,
     NewState As SpeechRecognizerState)

Parameters

  • StreamNumber
    Specifies the stream number.
  • StreamPosition
    Specifies the position within the stream.
  • NewState
    A SpeechRecognizerState constant specifying the new state of the speech recognition (SR) engine.

Example

The following Visual Basic form code demonstrates the use of the RecognizerStateChange event. The application displays the recognition text but also has a button to control the SR engine's state (also called the recognizer). Click this button to toggle the recognizer state between Active and Inactive. The application also beeps after a state change.

To run this code, create a form with the following controls:

  • A command button called Command1
  • A label called Label1

Paste this code into the Declarations section of the form.

The Form_Load procedure creates and activates a dictation grammar.

  Public WithEvents RC As SpSharedRecoContext
Public myGrammar As ISpeechRecoGrammar

Private Sub Command1_Click()
    If RC.Recognizer.State = SRSActive Then
        RC.Recognizer.State = SRSInactive
        Command1.Caption = "SRSInactive"
    Else
        RC.Recognizer.State = SRSActive
        Command1.Caption = "SRSActive"
    End If
End Sub

Private Sub Form_Load()
    Set RC = New SpSharedRecoContext

    Set myGrammar = RC.CreateGrammar
    myGrammar.DictationSetState SGDSActive

    Command1.Caption = "SRSActive"
End Sub

Private Sub RC_Recognition(ByVal StreamNumber As Long, ByVal StreamPosition As Variant, ByVal RecognitionType As SpeechLib.SpeechRecognitionType, ByVal Result As SpeechLib.ISpeechRecoResult)
    Label1.Caption = Result.PhraseInfo.GetText
End Sub

Private Sub RC_RecognizerStateChange(ByVal StreamNumber As Long, ByVal StreamPosition As Variant, ByVal NewState As SpeechLib.SpeechRecognizerState)
    Beep
End Sub