Interface: ISpeechRecoGrammar
DictationLoad Method
The DictationLoad method loads a dictation topic into the grammar.
ISpeechRecoGrammar.DictationLoad(
[TopicName As String = ""],
[LoadOption As SpeechLoadOption = SLOStatic]
)
Parameters
- TopicName
- [Optional] Specifies a dictation topic. The default value is the empty string.
- LoadOption
- [Optional] Specifies whether the grammar is to be loaded for static or dynamic use. The default is static.
Return Value
None.
Remarks
SAPI currently defines one specialized dictation topic: SPTOPIC_SPELLING. SR engines are not required to support specialized dictation topics (including spelling). When using another manufacturer's SR engine, consult its documentation for details.
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 a command button called Command1 and 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 inactivates 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