How Tos

Last reviewed: 7/15/2011

Article ID: H071108

HOW: Recognizing with a multi-grammar context

The information in this article applies to:

  • Developer Workbench 2011
  • GrammarKit 4
  • SpeechKit 7

Summary

Chant Developer Workbench 2011, GrammarKit 4, and SpeechKit 7 provide support for a new speech resource type CSRContext that serves as a container object for one or more grammars.

More Information

The CSRContext resource provides a way to combine two or more grammars to be compiled and loaded together when activated. This is required in cases where grammar rules are exported by one grammar and imported by another.

You can precompile a CSRContext resource with GrammarKit and presist the binary to a file. You can define, enable, and disable the compiled binary a CSRNativeGrammarVocab resource with SpeechKit.

Testing multi-grammar context with Chant Developer Workbench

Chant Developer Workbench 2011 introduces support for a new document type: Speech Recognition Context. The editor for this document type is XML-based and provides a way to define and test one or more command, grammar, and dictation vocabularies. It provides a way to test dynamic grammars by defining phrase lists that are set programmatically at runtime.

A speech recognition context is a runtime object comprised of one or more vocabulary resources from which to recognize speech. Some recognizers load context binary instead of grammar binary for runtime efficiency and to support importing and exporting rules across grammars. The steps to create a context with Chant GrammarKit are as follows:

  1. Select the File->New->Speech Recognition Context menu item or click the New Standard toolbar button and select Speech Recognition Context to create one in a document window.
  2. Select the Speech->Create Context... menu item, click the Create Context Speech toolbar button and select the speech engine API for which this context is based, or enter <recocontext and follow the intelliprompt suggestions will prompt you for the attribute in the declaration.
  3. Save your new context to a file by selecting the File->Save menu item or click the Save Standard toolbar button. You are prompted to confirm the file name.

A context consists of one or more vocabulary resource elements. You must add at least one valid vocabulary resource element to a context.

ElementChild ElementsAttributeDescription
recocontextcsrcontext
csrgrammarvocab
csrnativegrammarvocab
csrcommandvocab
csrremotevocab
apiThe speech recognition engine API used to compile and activate the context.
csrcontextcsrgrammarvocabsyntaxThe grammar syntax of the context grammars.
csrcommandvocabcsrvocabphrasenameThe name of the command vocabulary.
csrdictationvocabnameThe name of recognizer's dictation vocabulary.
csrgrammarvocabcsrvocablistname
syntax
compileroption
The file name of the grammar vocabulary.
The grammar syntax.
Grammar compiler option used when compiling grammar.
csrnativegrammarvocabcsrvocablistname
syntax
activatefield
startfield
stopfield
The file name of the grammar binary.
The grammar syntax.
The VoCon 1-shot (2-pass) activate field.
The VoCon 1-shot (2-pass) start field.
The VoCon 1-shot (2-pass) stop field.
csrvocablistcsrvocabphrasenameThe name of the rule for this list.
csrvocabphraseCommand vocabulary or list phrase text.
csrremotevocabVoCon Hybrid NMAS query.

Compiling multi-grammar context with GrammarKit

The GrammarKit 4 CompileResource2 method is for compiling CSRContext resources. CSRContext resources enable VoCon 3 and later grammars that import/export rules to be compiled under the same context.

If compiled output is to be saved, you must specify the type of result object format needed.

The following example illustrates compiling grammars.

private Chant.GrammarKit.NChantGM NChantGM1;
// Instantiate NChantGM object
NChantGM1 = new NChantGM(this);
NChantGM1.SetNumberProperty(ChantNumberProperty.CNPEngineAPI, (int)ChantEngineAPI.CEVoCon4);
// Win32 - Set the path to the VoCon runtime libraries
NChantGM1.SetStringProperty(ChantStringProperty.CSPEnginePath, "C:\\Program Files\\Nuance\\vocon3200\\EDS_v4_1\\bin\\winx86rls");
// Win32 - Set the file name of CLC model
NChantGM1.SetStringProperty(ChantStringProperty.CSPCLCModel, "C:\\Program Files\\Nuance\\vocon3200\\EDS_v4_1\\models\\clc_enu_cfg3_v1_0_0.dat");
// Win32 - Or set the file name of DDG2P model
//NChantGM1.SetStringProperty(ChantStringProperty.CSPDDG2PModel, "C:\\Program Files\\Nuance\\vocon3200\\EDS_v4_1\\models\\ddg2p_enu_vadvde_ttsasr_large_v2_1_3.dat");

// Define Context
int contextID = NChantGM1.DefineResource(ChantSpeechResource.CSRContext, "mycontext", ChantGrammarSyntax.CGSVoConBNF2);

// Define Grammars
int vocab1ID = NChantGM1.DefineResource(ChantSpeechResource.CSRGrammarVocab, "myvocab1.bnf", ChantGrammarSyntax.CGSVoConBNF2);
int vocab2ID = NChantGM1.DefineResource(ChantSpeechResource.CSRGrammarVocab, "myvocab2.bnf", ChantGrammarSyntax.CGSVoConBNF2);

// Add grammars to context
NChantGM1.AddResource(ChantSpeechResource.CSRContext, contextID, vocab1ID);
NChantGM1.AddResource(ChantSpeechResource.CSRContext, contextID, vocab2ID);

// Compile a grammar resource
NChantGM1.CompileResource2(ChantSpeechResource.CSRContext, contextID);
// Compile a grammar resource and save results to file
NChantGM1.CompileResource2(ChantSpeechResource.CSRContext, contextID, "mycontext.dat", ChantCompileResult.CCRFile, 0, ChantCompileOption.CCPAsynchronous);

Recognizing with multi-grammar context with SpeechKit

The SpeechKit 7 DefineResource method supports the CSRContext resource. CSRContext resources enable VoCon 3 and later grammars that import/export rules to be compiled under the same context.

To recognize with a multi-grammar context, define a CSRContext resource and add the grammar to the context.

The following example illustrates recognizing with multi-grammar context:

private Chant.GrammarKit.NChantSR NChantSR1;
private NChantGrammar _NChantGrammar = null;
// Instantiate NChantSR object
NChantSR1 = new NChantSR(this);
NChantSR1.SetNumberProperty(ChantNumberProperty.CNPEngineAPI, (int)ChantEngineAPI.CEVoCon4);
// Win32 - Set the path to the VoCon runtime libraries
NChantSR1.SetStringProperty(ChantStringProperty.CSPEnginePath, "C:\\Program Files\\Nuance\\vocon3200\\EDS_v4_1\\bin\\winx86rls");
// Win32 - Set the file name of CLC model
NChantSR1.SetStringProperty(ChantStringProperty.CSPCLCModel, "C:\\Program Files\\Nuance\\vocon3200\\EDS_v4_1\\models\\clc_enu_cfg3_v1_0_0.dat");
// Win32 - Or set the file name of DDG2P model
//NChantSR1.SetStringProperty(ChantStringProperty.CSPDDG2PModel, "C:\\Program Files\\Nuance\\vocon3200\\EDS_v4_1\\models\\ddg2p_enu_vadvde_ttsasr_large_v2_1_3.dat");

// Define Context
int contextID = NChantSR1.DefineResource(ChantSpeechResource.CSRContext, "mycontext", ChantResourceFunction.CRFNone, null, null, (int)ChantGrammarSyntax.CGSVoConBNF2, 0);

// Add grammars to context
NChantSR1.AddResource(ChantSpeechResource.CSRContext, contextID, "myvocab1.bnf");
NChantSR1.AddResource(ChantSpeechResource.CSRContext, contextID, "myvocab2.bnf");

// Load and enable context
NChantSR1.EnableResource(ChantSpeechResource.CSRContext, contextID);

// Disable it
NChantSR1.DisableResource(ChantSpeechResource.CSRContext, contextID);