How Tos

Last reviewed: 5/1/2012

Article ID: H051203

HOW: Learning about the new Chant Application Framework Vocabulary and UI Management classes

The information in this article applies to:

  • GrammarKit 4
  • SpeechKit 7

Summary

New Chant Application Framework classes provide an efficient way to manage vocabularies and speech enable UI elements.

These new classes obviate the need to manage resources with resource identifiers using the DefineResource, AddResource, DisableResource, EnableResource, and RemoveResource methods.

Instead, the class objects can be instantiated and have methods for adding, disabling, enabled, and removing items directly.

More Information

The following classes are new or are updated with new methods and available in C++, CBuilder, Delphi, Java, and .NET Framework:

Chant ProductClass NameSpeech ResourceDescription
GrammarKitChantGMContextCSRContextNew class that represents a speech recognition context for compiling multiple grammars.
GrammarKitChantGrammarNew constructor for instantiation and new Compile method.
SpeechKitChantComboBoxCSRComboBoxNew class that represents a combobox control.
SpeechKitChantCommandVocabCSRCommandVocabNew class the represents a command vocabulary.
SpeechKitChantDictationVocabCSRDictationVocabNew class that represents a dictation vocabulary.
SpeechKitChantDragonBoxCSRDgnDictCustomNew class that represents a Dragon NaturallySpeaking dictation custom edit control.
SpeechKitChantGrammarVocabCSRGrammarVocabNew class that represents a grammar vocabulary.
SpeechKitChantListBoxCSRListBoxNew class that represents a listbox control.
SpeechKitChantMenuCSRMenuNew class that represents a menu.
SpeechKitChantNativeGrammarVocabCSRNativeGrammarVocabNew class that represents a compiled grammar vocabulary.
SpeechKitChantRemoteVocabCSRRemoteVocabNew class that represents a remote vocabulary.
SpeechKitChantSRContextCSRContextNew class that represents a speech recognition context.
SpeechKitChantSRCommandCSRCommandNew class that represents a voice command.
SpeechKitChantSRMessageBoxCSRMessageBoxNew class that represents a messagebox dialog.
SpeechKitChantSystemMenuCSRSystemMenuNew class that represents a system menu.
SpeechKitChantTextBoxCSREditNew class that represents an edit control.
SpeechKitChantTTSCommandCSRCommandNew class that represents a text-to-speech command.
SpeechKitChantTTSMessageBoxCSRMessageBoxNew class that represents a messagebox dialog.
SpeechKitChantWindowCSRWindowNew class that represents an application window control.
SpeechKitChantWPFWindowCSRWindowNew class that represents a WPF window control.

The following example illustrates generating and compiling a Microsoft SAPI 5 XML grammar:

private Chant.GrammarKit.NChantGM NChantGM1;
private NChantGrammar _NChantGrammar = null;
// Instantiate NChantGM object
NChantGM1 = new NChantGM(this);

// Build Colors grammar
_NChantGrammar = new NChantGrammar(NChantGM1, "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" };
nChantGrammarList.AddPhrases(colors);

// Generate grammar source
string grammarSource = _NChantGrammar.GenerateGrammar(ChantGrammarSyntax.CGSSAPI5XML);

// Compile a grammar
_NChantGrammar.Compile("ChantGrammarSyntax.CGSSAPI5XML");

// Compile a grammar and save results to file
_NChantGrammar.Compile(ChantGrammarSyntax.CGSSAPI5XML, "mygrammar.dat");

The following example illustrates using a command vocabulary:

// Define the vocabulary
NChantCommandVocab nChantCommandVocab = new NChantCommandVocab(NChantSR1, "commands");

// Add commands to the vocabulary
nChantCommandVocab.AddCommand("Start Dictation");
nChantCommandVocab.AddCommand("Stop Dictation");
nChantCommandVocab.AddCommand("Show Dialog");

// Enable the vocabulary
nChantCommandVocab.Enable();

// Disable the vocabulary
nChantCommandVocab.Disable();

The following example illustrates voice commands:

// Define general navigation commands for use with list box and combo box
// These are generic key input simulations
// VK_UP x26
NChantSRCommand selectPreviousCmd = new NChantSRCommand(NChantSR1, "select previous", ChantResourceFunction.CRFKeyInput, null, null, 0x26);
// VK_DOWN x28
NChantSRCommand selectNextCmd = new NChantSRCommand(NChantSR1, "select next", ChantResourceFunction.CRFKeyInput, null, null, 0x28);

// Enable the voice commands
selectPreviousCmd.Enable();
selectNextCmd.Enable();

// Disable the voice commands
selectPreviousCmd.Disable();
selectNextCmd.Disable();