How do I deploy with binary grammars?
Last reviewed: 9/10/2008
HOW Article ID: H090804
The information in this article applies to:
- SpeechKit 6
Summary
SpeechKit vocabulary management, to date, supported compiling and enabling grammars passed in source form via buffers, files, and streams. Precompiled binary grammars were only supported as files.
For tighter integration with GrammarKit and provide more application usage scenarios, SpeechKit 6 supports precompiled binary grammars as buffers and streams.
More Information
Two new vocabulary typesCSRBufferGrammarVocab and CSRStreamGrammarVocabare supported in SpeechKit 6 to define and enable vocabularies from precompiled grammars.
Applications can now pass grammar binary via buffers and streams to define and enable grammar vocabularies. This enables your application to manage grammars without requiring grammar binary to be in a file. Grammars can be precompiled before deploying applications, compiled as part of your application installation and configuration, and/or at runtime as part of your application facilities.
The following example illustrates compiling a grammar vocabulary with GrammarKit and managing it at run time with SpeechKit.
// Register for callbacks
ChantGM.RegisterCallback(CCGMDone)
ChantSR.RegisterCallback(CCSRHasPhrase)
// Compile the grammar
NChantGM1.CompileResource("c:\\pathtomyfile\\mygrammar.xml", 0, CCOFile, CGSSAPI5XML, "", CCRBuffer, 0, ChantCompileOption.CCPAsynchronous)
// Define and enable the grammar vocabulary in the ChantGM HasEvent handler when the compile is complete
// Get the number of events
numberOfEvents = NChantGM1.GetResourceCount(ChantSpeechResource.CSREvent, 0, 0)
for (i= 0; i < numberOfEvents; i++)
{
// Get the event from the event queue
aChantGMEvent = ChantGM.GetChantGMEvent(0)
if (aChantGMEvent.ChantCallback == CCGMDone)
{
if (aChantGMEvent.Bytes > 0)
{
// Define the grammar vocabulary
GrammarVocabID = ChantSR.DefineResource(CSRBufferGrammarVocab, aChantGMEvent.Buffer, aChantGMEvent.Bytes)
ChantSR.EnableResource(CSRBufferGrammarVocab, GrammarVocabID)
}
}
// Remove the event from the event queue
ChantGM.RemoveResource(ChantSpeechResource.CSREvent, 0, "")
}