Share via


SpeechRecoContext Hypothesis Event (SAPI 5.3)

Microsoft Speech API 5.3

Interface: ISpeechRecoContext Events

Hypothesis Event

The Hypothesis event occurs when the SR engine produces a hypothesis.

A hypothesis is an interim recognition result. Each time the engine attempts a recognition it generates an interim results and Hypothesis events are sent out. A hypothesis may or may not be close to the final version of the recognition. In fact, a hypothesis may not bear any likeness to the final result due to the sound quality, idiomatic phrasing, or uncommon word or phrase usage.

The member Result is a valid recognition result and may be used in the same way as a Recognition event. However, the values are interim and could change for the next Hypothesis event.

  
    SpeechRecoContext.Hypothesis(
     StreamNumber As Long,
     StreamPosition As Variant,
     Result As ISpeechRecoResult)

Parameters

  • StreamNumber
    Specifies the stream number.
  • StreamPosition
    Specifies the position within the stream.
  • Result
    An ISpeechRecoResult object containing the recognition results.

Example

The following Visual Basic form code demonstrates the use of the Hypothesis event. The application displays all the hypotheses for the current recognition attempt and then displays the final recognition.

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 PhraseStart event clears the display each time so the current hypothesis is displayed. For longer recognitions, a larger Label1 may be used or changed 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)
    Label1.Caption = Label1.Caption & Result.PhraseInfo.GetText & vbCrLf
End Sub

Private Sub RC_PhraseStart(ByVal StreamNumber As Long, ByVal StreamPosition As Variant)
    Label1.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)
    Label2.Caption = Result.PhraseInfo.GetText
End Sub