How Tos

Last reviewed: 7/15/2011

Article ID: H071141

HOW: Managing SAPI 5 XML 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 SAPI 5 XML grammars.

More Information

The SAPI 5 XML grammar text file format is an Extensible Markup Language (XML) grammar adapted for speech recognition.

Creating, Editing, and Testing SAPI 5 XML Grammars

Chant Developer Workbench 2011 continues support for creating, editing, and testing SAPI 5 XML grammars. The new editor provides intelliprompt assistance for fast syntax input and editing.

The steps to create a SAPI 5 XML grammar with Chant Developer Workbench and GrammarKit are as follows:

  1. Select the File->New->Speech Recognition Grammar->SAPI 5 Grammar menu item or click the New Standard toolbar button and select SAPI 5 Grammar to create one 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.
  2. 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 SAPI 5 XML Grammars

GrammarKit 4 continues support for dynamically generating and compiling SAPI 5 XML grammars.

The following example illustrates generating a SAPI 5 XML grammar:

private Chant.GrammarKit.NChantGM NChantGM1;
private NChantGrammar _NChantGrammar = null;
// Instantiate NChantGM object
NChantGM1 = new NChantGM(this);
// 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]);
}
string grammarSource = _NChantGrammar.GenerateGrammar(ChantGrammarSyntax.CGSSAPI5XML);

Recognizing with SAPI 5 XML Grammars

SpeechKit 7 continues support for recognizing with SAPI 5 XML grammars.

The following example illustrates defining, enabling, and disabling a SAPI 5 XML grammar resource for speech recognition.

private Chant.SpeechKit.NChantSR NChantSR1;
// Instantiate NChantSR object
NChantSR1 = new NChantSR(this);
// Define a grammar vocabulary
int grammarVocabID = NChantSR1.DefineResource(ChantSpeechResource.CSRGrammarVocab, "mygrammar.xml");
// Load and enable grammar vocabulary
NChantSR1.EnableResource(ChantSpeechResource.CSRGrammarVocab, grammarVocabID);
// Disable it
NChantSR1.DisableResource(ChantSpeechResource.CSRGrammarVocab, grammarVocabID);