ISpeechRecoGrammar DictationSetState method (Microsoft Speech Platform)

Microsoft Speech Platform SDK 11

Microsoft Speech Platform

Interface: ISpeechRecoGrammar

DictationSetState Method

The DictationSetState method sets the dictation topic state.


ISpeechRecoGrammar.DictationSetState(
     State As SpeechRuleState
)

Parameters

State
A SpeechRuleState constant that specifies the dictation topic state.

Return Value

None.


Example

The following Visual Basic form code demonstrates the use of the DictationLoad, DictationSetState, and DictationUnload methods. It creates a grammar, configures the grammar to perform both dictation and command and control (C and C) recognition, and toggles between the two types of 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.

The Form_Load procedure creates a grammar object, associates it with the system dictation lexicon and the Solitaire C and C grammar, and begins recognition in dictation mode. The Command1_Click procedure toggles the recognition mode between dictation and C and C. The Form_Unload procedure unloads the dictation grammar and deactivates the C and C grammar.


Option Explicit

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

Private Sub Command1_Click()
    On Error GoTo EH

    If Command1.Caption = "&Dictation;" Then
        MyGrammar.CmdSetRuleIdState 0, SGDSInactive     'C&C; off
        MyGrammar.DictationSetState SGDSActive          'Dictation on
        Command1.Caption = "&C; and C"
    Else
        MyGrammar.DictationSetState SGDSInactive        'Dictation off
        MyGrammar.CmdSetRuleIdState 0, SGDSInactive     'C&C; on
        Command1.Caption = "&Dictation;"
    End If

EH:
    If Err.Number Then ShowErrMsg
End Sub

Private Sub Form_Load()
    On Error GoTo EH

    'Create a RecoContext and its Grammar
    Set MyRecoContext = New SpSharedRecoContext
    Set MyGrammar = MyRecoContext.CreateGrammar

    'Get dictation grammar and set it inactive
    MyGrammar.DictationLoad "", SLOStatic
    MyGrammar.DictationSetState SGDSInactive

    'Get Command & Control grammar, and set it inactive
    MyGrammar.CmdLoadFromFile "C:\SOL.XML", SLOStatic
    MyGrammar.CmdSetRuleIdState 0, SGDSInactive

    'Set dictation active and set up Command1.Caption
    MyGrammar.DictationSetState SGDSActive
    Command1.Caption = "&C; and C"

EH:
    If Err.Number Then ShowErrMsg
End Sub

Private Sub Form_Unload(Cancel As Integer)
    On Error GoTo EH

    MyGrammar.DictationUnload
    MyGrammar.CmdSetRuleIdState 0, SGDSInactive

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