SpeechRecoContext EndStream Event (SAPI 5.3)

Speech API 5.3
Microsoft Speech API 5.3

Interface: ISpeechRecoContext Events

EndStream Event

The EndStream event occurs when the speech recognition engine encounters the end of an input audio stream.

     StreamNumber As Long,
     StreamPosition As Variant,
     StreamReleased As Boolean


Specifies the stream number.
Specifies the position within the stream.
Indicates that the stream was released. Usually, stopping a stream does not release it and StreamReleased should be False. However, if the stream is not associated with an audio device or if the stream ran out of data while in the run state, the stream will be both stopped and released; in this case, StreamReleased will be True.


The following Visual Basic form code demonstrates the use of the StartStream and EndStream events. The application displays the status of the stream and a stream number. It also displays a successful recognition if a stream is active.

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

  • A command button called Command1
  • Two labels called Label1 and Label2

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
Public fRecoEnabled As Boolean

Private Sub Command1_Click()
    If fRecoEnabled = True Then
        myGrammar.DictationSetState SGDSInactive
        fRecoEnabled = False
        myGrammar.DictationSetState SGDSActive
        fRecoEnabled = True
    End If
End Sub

Private Sub Form_Load()
    Set RC = New SpSharedRecoContext
    Set myGrammar = RC.CreateGrammar

    myGrammar.DictationSetState SGDSActive
    fRecoEnabled = True

    Command1.Caption = "Start Recognition"
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_EndStream(ByVal StreamNumber As Long, ByVal StreamPosition As Variant, ByVal StreamReleased As Boolean)
    Label2.Caption = "Stream stopped at position: " & StreamPosition
End Sub

Private Sub RC_StartStream(ByVal StreamNumber As Long, ByVal StreamPosition As Variant)
    Label2.Caption = "Stream number = " & Val(StreamNumber)
End Sub