ISpeechRecoGrammar Id property (Microsoft Speech Platform)

Microsoft Speech Platform SDK 11

Microsoft Speech Platform

Interface: ISpeechRecoGrammar

Id Property

The Id property returns the ID assigned to the grammar when it was created.

Syntax

Set: Not available.
Get: Variant = ISpeechRecoGrammar.Id

Parts

ISpeechRecoGrammar
The owning object.
Variant
Set: (This property is read-only).
Get: A Variant variable that gets the property value.

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 which owns 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()
    On Error GoTo EH

    Set RecoContext = New SpSharedRecoContext
    Set objGR1 = RecoContext.CreateGrammar(6)       'Create grammar with ID = 6
    Set objGR2 = RecoContext.CreateGrammar("7")     'Create grammar with ID = 7

EH:
    If Err.Number Then ShowErrMsg
End Sub

Private Sub GrammarSub(G As SpeechLib.ISpeechRecoGrammar)
    On Error GoTo EH

    G.RecoContext.Pause     'Pause the RecoContext that owns grammar
    MsgBox G.Id             'Display the Id
    G.RecoContext.Resume    'Resume the RecoContext

EH:
    If Err.Number Then ShowErrMsg
End Sub

Private Sub ShowErrMsg()

    ' Declare identifier:
    Dim T As String

    T = "Desc: " & Err.Description & vbNewLine
    T = T & "Err #: " & Err.Number
    MsgBox T, vbExclamation, "Run-Time Error"
    End

End Sub