You are reading help file online using chmlib.com
|
Interface: ISpeechRecoGrammar
The CmdLoadFromResource method loads a command and control grammar from a Win32 resource.
ISpeechRecoGrammar.CmdLoadFromResource(
hModule As Long,
ResourceName As Variant,
ResourceType As Variant,
LanguageId As Long,
[LoadOption As SpeechLoadOption = SLOStatic]
)
None.
The grammar resource must be a compiled SAPI 5 binary version of a context-free grammar (CFG).
Using this method will unload the currently loaded CFG or proprietary grammar.
The following Visual Basic form code demonstrates the use of the CmdLoadFromResource method. Before attempting to run this code, you must:
The Form_Load procedure creates a grammar object and loads it with the compiled Solitaire grammar contained in the DLL. There are no controls on this form; simply speak into your microphone. Phrases like "Move the red ten" or "Play the queen of hearts" will be recognized.
Option Explicit
Dim WithEvents C As SpSharedRecoContext
Dim G As ISpeechRecoGrammar
Dim hndRes As Long
' Change this constant to match the path
' of the SpeechDocs DLL on your machine!
Const lib As String = "C:\SpeechDocs.dll"
Const resType As String = "CFGGRAMMAR"
Const resName As Long = 101
Const langID As Long = &H409
Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" _
(ByVal lpLibFileName As String) As Long
Private Sub Form_Load()
Set C = New SpSharedRecoContext
Set G = C.CreateGrammar
' Obtain a handle to the executable holding the grammar as a resource
hndRes = LoadLibrary(lib)
' Load the grammar from the resource
G.CmdLoadFromResource hndRes, resName, resType, langID, SLOStatic
' Set all DefaultToActive rules active
' NOTE: The solitaire grammar happens to have DefaultToActive rules
' which is why we can activate them this way.
G.CmdSetRuleState "", SGDSActive
End Sub
Private Sub C_FalseRecognition( _
ByVal StreamNumber As Long, _
ByVal StreamPosition As Variant, _
ByVal result As SpeechLib.ISpeechRecoResult _
)
MsgBox "(not recognized!)"
End Sub
Private Sub C_Recognition( _
ByVal StreamNumber As Long, _
ByVal StreamPosition As Variant, _
ByVal RecognitionType As SpeechLib.SpeechRecognitionType, _
ByVal result As SpeechLib.ISpeechRecoResult _
)
MsgBox result.PhraseInfo.GetText
End Sub
You are reading help file online using chmlib.com
|