CHMlib Logo Leading Translation Management System for Translation Agencies, Top Translation Management Software for Freelance Translators, Time Tracking Software, Word Count, Character Count and Line Count Software, Computer Assisted Translation Tool for Easy Word Count, Clipboard Character Count Software, User-Friendly Translation Memory Software, Terminology Management Software, Terminology Management Server, Microsoft Glossary Software, Dictionary of Acronyms, Social Network for Translators and Translation Agencies, Acronyms and Abbreviations Search Engine, Russian Translation Lab, Ukrainian Translation Lab.
You are reading help file online using chmlib.com
CrisisHelper - First Aid in Tough Times of World Economic Crisis


Intelligent Interface Technologies Home Page Microsoft Speech SDK

Speech Automation 5.1

Interface: ISpeechRecoGrammar

CmdLoadFromMemory Method


The CmdLoadFromMemory method loads a compiled speech grammar from memory.


The

ISpeechRecoGrammar.CmdLoadFromMemory(
     GrammarData As Variant,
     [LoadOption As SpeechLoadOption = SLOStatic]
)

Parameters

GrammarData
Specifies the GrammarData.
LoadOption
[Optional] Specifies whether the grammar is to be loaded for static or dynamic use. The default is static.

Return Value

None.


Example

The following Visual Basic form code demonstrates use of the CmdLoadFromMemory method. To run this code, create a form and paste this code into the Declarations section.

The Form_Load procedure creates a recognition context and a CFG grammar object. It adds a simple rule to the grammar, and saves the grammar data to a Variant variable with the CommitAndSave method. It then uses the CmdLoadFromMemory method to load the second grammar object with the grammar data in the Variant variable. Finally, it activates the rule in the second grammar.

If the computer has a microphone, run this code and speak the phrase, "Hello, world" into the microphone. The recognition context's Recognition and FalseRecognition event procedures display messages indicating successful or unsuccessful recognition.


Option Explicit

Dim WithEvents recoCtx As SpSharedRecoContext
Dim grammar As ISpeechRecoGrammar
Dim grammar2 As ISpeechRecoGrammar
Dim gRules As ISpeechGrammarRules
Dim gRule As ISpeechGrammarRule
Dim state As ISpeechGrammarRuleState

Dim buffer As String    ' Any error information when committing and saving the grammar
Dim gData As Variant    ' The contents of the grammar held in memory

' Typically there is no reason to do something like this.
' This is just the simplest possible example to demonstrate the use of
' ISpeechRecoGrammar.CmdLoadFromMemory.

Private Sub Form_Load()

    Set recoCtx = New SpSharedRecoContext
    Set grammar = recoCtx.CreateGrammar
    Set gRules = grammar.Rules
    
    ' Grammar has one rule, one state, and one transition
    Set gRule = gRules.Add("greeting", SRATopLevel, 1)
    Set state = gRule.InitialState
    state.AddWordTransition Nothing, "hello world", " "
    
    ' Save the grammar to memory (contents saved in gData)
    gData = grammar.Rules.CommitAndSave(buffer)
    
    Set grammar2 = recoCtx.CreateGrammar                'Second grammar
    grammar2.CmdLoadFromMemory gData, SLOStatic         'Load from memory
    grammar2.CmdSetRuleState "greeting", SGDSActive     'Set rule active
    
End Sub

Private Sub recoCtx_FalseRecognition(ByVal StreamNumber As Long, ByVal StreamPosition As Variant, ByVal Result As SpeechLib.ISpeechRecoResult)
    ' Gets here only when the phrase "hello world" is falsely recognized
    MsgBox "(not recognized!)"
End Sub

Private Sub recoCtx_Recognition(ByVal StreamNumber As Long, ByVal StreamPosition As Variant, ByVal RecognitionType As SpeechLib.SpeechRecognitionType, ByVal Result As SpeechLib.ISpeechRecoResult)
    ' Gets here only when the phrase "hello world" is recognized
    MsgBox Result.PhraseInfo.GetText
End Sub


You are reading help file online using chmlib.com

If you want your help file to be removed or added please send e-mail to chmlibcom@gmail.com
Partner sites: Logo Design, Simple Anti-Crisis Accounting Software, Voice Search for Web