Share via


ISpeechRecoGrammar State Property (SAPI 5.3)

Microsoft Speech API 5.3

Interface: ISpeechRecoGrammar

State Property

The State property gets and sets the operational status of the speech grammar.

The status consists of a SpeechGrammarState constant; its three states can be summarized as enabled, disabled, and exclusive.

Syntax

Set: ISpeechRecoGrammar.State = SpeechGrammarState
Get: SpeechGrammarState = ISpeechRecoGrammar.State

Parts

  • ISpeechRecoGrammar
    The owning object.
  • SpeechGrammarState
    Set: A SpeechGrammarState constant that sets the property.
    Get: A SpeechGrammarState constant that gets the property.

Example

The following Visual Basic form code demonstrates the use of the State property. The grammar is disabled while the CmdLoadFromFile method loads the grammar, and enabled when the load has completed.

To run this code, create a form (it need not have any controls) and paste the code into the Declarations section of the form.

  
Option Explicit

Private Sub Form_Load()
    On Error GoTo EH

    Dim MyRecoContext As SpeechLib.SpSharedRecoContext
    Dim MyGrammar As SpeechLib.ISpeechRecoGrammar

    Set MyRecoContext = New SpSharedRecoContext
    Set MyGrammar = MyRecoContext.CreateGrammar()

    MyGrammar.State = SGSDisabled       'Disable grammar while loading

    MyGrammar.CmdLoadFromFile ("c:\sol.xml")

    MyGrammar.State = SGSEnabled        'Re-enable when done loading

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