Share via


SpeechRecoContext PhraseStart Event (SAPI 5.3)

Microsoft Speech API 5.3

Interface: ISpeechRecoContext Events

PhraseStart Event

The PhraseStart event occurs when the speech recognition (SR) engine identifies the start of a phrase.

  
    SpeechRecoContext.PhraseStart(
     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 PhraseStart event but also StartStream, SoundStart, SoundEnd, Hypothesis, and Recognition since they can be related. The application displays all the hypotheses for the current recognition attempt in one window and the other events in a second window.

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

  • 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. The SoundStart event clears the displays each time. For longer recognitions, a larger Label2 may be used or change it to a scrolling text box.

  Public WithEvents RC As SpSharedRecoContext
Public myGrammar As ISpeechRecoGrammar

Private Sub Form_Load()
    Set RC = New SpSharedRecoContext

    Set myGrammar = RC.CreateGrammar
    myGrammar.DictationSetState SGDSActive
End Sub

Private Sub RC_Hypothesis(ByVal StreamNumber As Long, ByVal StreamPosition As Variant, ByVal Result As SpeechLib.ISpeechRecoResult)
    Label2.Caption = Label2.Caption & Result.PhraseInfo.GetText & vbCrLf
End Sub

Private Sub RC_PhraseStart(ByVal StreamNumber As Long, ByVal StreamPosition As Variant)
    Label1.Caption = Label1.Caption & "      Phrase start detected at position : " & StreamPosition & vbCrLf
    Label2.Caption = ""
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 = Label1.Caption & Result.PhraseInfo.GetText
End Sub

Private Sub RC_SoundEnd(ByVal StreamNumber As Long, ByVal StreamPosition As Variant)
Label1.Caption = Label1.Caption & "   Sound end" & vbCrLf
End Sub

Private Sub RC_SoundStart(ByVal StreamNumber As Long, ByVal StreamPosition As Variant)
    Label1.Caption = "   Sound begin" & vbCrLf
End Sub

Private Sub RC_StartStream(ByVal StreamNumber As Long, ByVal StreamPosition As Variant)
    Label1.Caption = "Stream Number: " & StreamNumber & vbCrLf
    Label2.Caption = ""
End Sub