Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

SpeechRecoContext StartStream Event (SAPI 5.3)

Speech API 5.3
Microsoft Speech API 5.3

Interface: ISpeechRecoContext Events

StartStream Event


The StartStream event occurs when the speech recognition (SR) engine encounters the start of an audio input stream.

The stream number of each new stream will be incremented from the last stream number, so that each value is unique to the application's lifespan. Stream numbers may be used to track input sources. In the case of recognizing wav files in a batch environment, for instance, stream numbers may be used to uniquely identify the source. In other cases, a StreamStart event can indicate the beginning of a new recognition attempt.


SpeechRecoContext.StartStream(
     StreamNumber As Long,
     StreamPosition As Variant
)

Parameters

StreamNumber
Specifies the stream number.
StreamPosition
Specifies the position within the stream.

Remarks

For speech processing, the SR engine must perform the following sequence: Stream start, sound start and phrase start. A stream start indicates a valid stream is ready for audio input. The stream persists unless the recognition context is disabled or the associated grammar is deactivated. The sound start indicates a sound level has been detected. However, it is possible the SR engine could stop that recognition attempt if the input sound were questionable. For example, if the sound were a constant level or if above or below pre-determined sound levels. If the sound level is acceptable and variable, a phrase start is initiated and it is assumed to be the beginning of a recognition attempt.

Example

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
    Else
        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
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.