SpeechRecoContext CreateResultFromMemory Method

Microsoft Speech SDK

Intelligent Interface Technologies Home Page Microsoft Speech SDK

Speech Automation 5.1

Interface: ISpeechRecoContext

CreateResultFromMemory Method


The CreateResultFromMemory method creates a recognition result object from a saved recognition result.

The result must have been created with ISpeechRecoResult.SaveToMemory.


SpeechRecoContext.CreateResultFromMemory(
     ResultBlock As Variant
) As ISpeechRecoResult

Parameters

ResultBlock
A Variant variable containing a saved recognition result.

Return Value

An ISpeechRecoResult object.


Example

The following Visual Basic form code demonstrates the use of the SpeechRecoContext.CreateResultFromMemory and ISpeechRecoResult.SaveToMemory. The application displays the text of the current recognition as well as the previous one. This application also plays the the retained audio associated with the last recognition.

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

  • A command button called Command1
  • Paste this code into the Declarations section of the form.

    Public WithEvents RC As SpSharedRecoContext
    Public myGrammar As ISpeechRecoGrammar
    Dim gLastPhrase As Variant
    
    Private Sub Form_Load()
        Set RC = New SpSharedRecoContext
        RC.RetainedAudio = SRAORetainAudio
        Set myGrammar = RC.CreateGrammar
        
        myGrammar.DictationSetState SGDSActive
        gLastPhrase = Empty
    End Sub
    
    Private Sub RC_Recognition(ByVal StreamNumber As Long, ByVal StreamPosition As Variant, ByVal RecognitionType As SpeechLib.SpeechRecognitionType, ByVal Result As SpeechLib.ISpeechRecoResult)
        If IsEmpty(gLastPhrase) = False Then
            Dim GetRecoResult As ISpeechRecoResult
            Set GetRecoResult = RC.CreateResultFromMemory(gLastPhrase)
            
            savedText = GetRecoResult.PhraseInfo.GetText()
            Label1.Caption = "Last phrase: " & savedText
            GetRecoResult.SpeakAudio
        End If
        
        Label1.Caption = Label1.Caption & vbCrLf & "New phrase: " & Result.PhraseInfo.GetText
        
        Dim thePhrase As Variant
        gLastPhrase = Result.SaveToMemory
    End Sub