ISpeechRecoGrammar RecoContext property

Microsoft Speech SDK

Intelligent Interface Technologies Home Page Microsoft Speech SDK

Speech Automation 5.1

Interface: ISpeechRecoGrammar

RecoContext Property


The RecoContext property returns the RecoContext object that created the grammar.

Syntax

Set: Not available.
Get: ISpeechRecoContext = ISpeechRecoGrammar.RecoContext

Parts

ISpeechRecoGrammar
The owning object.
ISpeechRecoContext
Set: (This property is read-only).
Get: An ISpeechRecoContext object which instantiates the RecoContext object that created the grammar.

Example

The following Visual Basic form code demonstrates the use of the Id and RecoContext properties. To run this code, create a form with the following controls:

  • Two command buttons called Command1 and Command2
  • Paste this code into the Declarations section of the form.

    The Form_Load procedure creates a recognition context with two ISpeechRecoGrammar objects. The ISpeechRecoGrammar objects are created with Id properties of 6 and 7. The Command1 and Command2 procedures each send one of the grammar objects to the GrammarSub procedure as parameters. The GrammarSub procedure displays the ID of the grammar object parameter, and uses the parameter's RecoContext property to pause and resume the recognition context that owns the grammar.

    There is no special significance to the Id property values of 6 or 7; these values are arbitrary. Additionally, the Pause and Resume methods in the GrammarSub procedure are intended simply to show how the grammar's RecoContext property provides access to the methods and properties of the recognition context that created the grammar.


    Option Explicit
    
    Dim RecoContext As SpeechLib.SpSharedRecoContext
    Dim objGR1 As SpeechLib.ISpeechRecoGrammar
    Dim objGR2 As SpeechLib.ISpeechRecoGrammar
    
    Private Sub Command1_Click()
        Call GrammarSub(objGR1)
    End Sub
    
    Private Sub Command2_Click()
        Call GrammarSub(objGR2)
    End Sub
    
    Private Sub Form_Load()
    
        Set RecoContext = New SpSharedRecoContext
        Set objGR1 = RecoContext.CreateGrammar(6)       'Create grammar with ID = 6
        Set objGR2 = RecoContext.CreateGrammar("7")     'Create grammar with ID = 7
    
    End Sub
    
    Private Sub GrammarSub(G As SpeechLib.ISpeechRecoGrammar)
        
        G.RecoContext.Pause     'Pause the RecoContext that owns grammar
        MsgBox G.Id             'Display the Id
        G.RecoContext.Resume    'Resume the RecoContext
    
    End Sub