How Tos

Last reviewed: 7/15/2011

Article ID: H071103

HOW: Managing VoCon Grammars

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 L&H BNF V1.0, V1.1, and V2.0 grammars.

More Information

The L&H BNF grammar is a Backus-Naur Form (BNF) grammar adapted for speech recognition. There are 3 syntax versions: V1.0, V1.1, and V2.0.

The #BNF+EM V1.0; statement that appears as the first line in the grammar defines the syntax version.

Creating, Editing, and Testing L&H BNF Grammars

Chant Developer Workbench 2011 introduces support for creating, editing, and testing all three versions of L&H BNF grammar syntax. The updated editors provide intelliprompt assistance for fast syntax input and editing.

The steps to create an L&H BNF grammar with Chant Developer Workbench and GrammarKit are as follows:

  1. Select the File->New->Speech Recognition Grammar->L&H BNF V1.0 Grammar menu item or click the New Standard toolbar button and select L&H BNF V1.0 Grammar to create a V1.0 grammar in a document window.
  2. Select the File->New->Speech Recognition Grammar->L&H BNF V1.1 Grammar menu item or click the New Standard toolbar button and select L&H BNF V1.1 Grammar to create a V1.1 grammar in a document window.
  3. Select the File->New->Speech Recognition Grammar->L&H BNF V2.0 Grammar menu item or click the New Standard toolbar button and select L&H BNF V2.0 Grammar to create a V2.0 grammar in a document window. Note if you do not see any grammar types listed in the menu, then you need to run the Chant Software Unlock utility to begin your evaluation, your GrammarKit evaluation has expired, or you need to register and unlock your licensed copy with a serial number.
  4. Save your new grammar 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.

Dynamically Generating L&H BNF Version-specific Grammars

GrammarKit 4 introduces support for dynamically generating and compiling L&H BNF version-specific grammars.

The following example illustrates generating a L&H BNF grammar:

private Chant.GrammarKit.NChantGM NChantGM1;
private NChantGrammar _NChantGrammar = null;
// 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");
// Build Colors grammar
_NChantGrammar = NChantGM1.CreateGrammar("Colors");
_NChantGrammar.AddComment("This is the list of colors");
NChantGrammarRule nChantGrammarRule = _NChantGrammar.AddRule("Color");
NChantGrammarList nChantGrammarList = nChantGrammarRule.AddList("colorlist");
string[] colors = { "red", "blue", "green", "yellow", "pink", "purple", "brown", "orange" };
for (int i = 0; i < colors.Length; i++)
{
nChantGrammarList.AddPhrase(colors[i]);
}
// Generate L&H V1.0 grammar
string grammarSource = _NChantGrammar.GenerateGrammar(ChantGrammarSyntax.CGSVoConBNF);
// Generate L&H V1.1 grammar
string grammarSource = _NChantGrammar.GenerateGrammar(ChantGrammarSyntax.CGSVoConBNF1);
// Generate L&H V2.0 grammar
string grammarSource = _NChantGrammar.GenerateGrammar(ChantGrammarSyntax.CGSVoConBNF2);

Recognizing with L&H BNF Version-specific Grammars

To recognize speech with L&H BNF version-specific grammar, simply use the SpeechKit ChantSR DefineResource method to define a CSRNativeGrammarVocab (binary) or CSRGrammarVocab (source) resource with the file name of the grammar. Use the EnableResource and DisableResource methods to activate and deactivate the grammar.

VoCon 3200 V2 supports V1.0 grammars. VoCon V3 supports V1.1 grammars. VoCon V4 supports V2.0 grammars.

// Define a grammar vocabulary
int GrammarVocabID = NChantSR1.DefineResource(ChantSpeechResource.CSRGrammarVocab, "mygrammar.bnf");
// Load and enable grammar vocabulary
NChantSR1.EnableResource(ChantSpeechResource.CSRGrammarVocab, grammarVocabID);
// Disable it
NChantSR1.DisableResource(ChantSpeechResource.CSRGrammarVocab, grammarVocabID);