What are the new Chant Application Framework Vocabulary and UI Management Classes?

Last reviewed: 5/1/2012

HOW Article ID: H051203

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");
        

CChantGM* m_pChantGM;  // ChantGM object
CChantGrammar* m_pChantGrammar;  // ChantGrammar object
// Instantiate ChantGM object
m_pChantGM = new CChantGM();

// Build Colors grammar
m_pChantGrammar = new CChantGrammar(m_pChantGM, L"Colors");
m_pChantGrammar->AddComment(L"This is the list of colors");
CChantGrammarRule* pChantGrammarRule = m_pChantGrammar->AddRule(L"Color");
CChantGrammarList* pChantGrammarList = pChantGrammarRule->AddList(L"colorlist");
wchar_t* colors[] = { L"red", L"blue", L"green", L"yellow", L"pink", L"purple", L"brown", L"orange" };
for (int i = 0; i < 8; i++)
{
    pChantGrammarList->AddPhrase(colors[i]);
}

// Generate grammar source
wchar_t* pszGrammar = m_pChantGrammar->GenerateGrammar(CGSSAPI5XML);

// Compile a grammar
m_pChantGrammar->Compile(CGSSAPI5XML);

// Compile a grammar and save results to file
m_pChantGrammar->Compile(CGSSAPI5XML, L"mygrammar.dat");
    

CChantGM* ChantGM1;  // ChantGM object
CChantGrammar* ChantGrammar1;  // ChantGrammar object
// Instantiate ChantGM object
ChantGM1 = new CChantGM();

// Build Colors grammar
ChantGrammar1 = new CChantGrammar(ChantGM1, "Colors");
ChantGrammar1->AddComment("This is the list of colors");
CChantGrammarRule* pChantGrammarRule = ChantGrammar1->AddRule("Color");
CChantGrammarList* pChantGrammarList = pChantGrammarRule->AddList("colorlist");
pChantGrammarList->AddPhrase("red");
pChantGrammarList->AddPhrase("blue");
pChantGrammarList->AddPhrase("green");
pChantGrammarList->AddPhrase("yellow");
pChantGrammarList->AddPhrase("pink");
pChantGrammarList->AddPhrase("purple");
pChantGrammarList->AddPhrase("brown");
pChantGrammarList->AddPhrase("orange");

// Generate grammar source
String sGrammar = ChantGrammar1->GenerateGrammar(CGSSAPI5XML);

// Compile a grammar
ChantGrammar1->Compile(CGSSAPI5XML);

// Compile a grammar and save results to file
ChantGrammar1->Compile(CGSSAPI5XML, "mygrammar.dat");

var
ChantGM1: TChantGM;
aTChantGrammar: TChantGrammar;
aTChantGrammarRule: TChantGrammarRule;
aTChantGrammarList: TChantGrammarList;
sGrammar: string;
begin
// Instantiate ChantGM object
ChantGM1 := TChantGM.Create();

// Build Colors grammar
aTChantGrammar := TChantGrammar.Create(ChantGM1, 'Colors');
aTChantGrammar.AddComment('This is the list of colors');
aTChantGrammarRule := aTChantGrammar.AddRule('Color');
aTChantGrammarList := aTChantGrammarRule.AddList('colorlist');
aTChantGrammarList.AddPhrase('red');
aTChantGrammarList.AddPhrase('blue');
aTChantGrammarList.AddPhrase('green');
aTChantGrammarList.AddPhrase('yellow');
aTChantGrammarList.AddPhrase('pink');
aTChantGrammarList.AddPhrase('purple');
aTChantGrammarList.AddPhrase('brown');
aTChantGrammarList.AddPhrase('orange');

// Generate grammar source
sGrammar := ChantGrammar.GenerateGrammar(CGSSAPI5XML);

// Compile a grammar
ChantGrammar.Compile(CGSSAPI5XML);

// Compile a grammar and save results to file
ChantGrammar.Compile(CGSSAPI5XML, 'mygrammar.dat');
end;
    

private JChantGM JChantGM1;
private JChantGrammar _JChantGrammar;
// Instantiate ChantGM object
JChantGM1 = new JChantGM();

// Build Colors grammar
_JChantGrammar = new JChantGrammar(JChantGM1, "Colors");
_JChantGrammar.addComment("This is the list of colors");
JChantGrammarRule jChantGrammarRule = _JChantGrammar.addRule("Color");
JChantGrammarList jChantGrammarList = jChantGrammarRule.addList("colorlist");
String[] colors = { "red", "blue", "green", "yellow", "pink", "purple", "brown", "orange" };
jChantGrammarList.addPhrases(colors);

// Generate grammar source
String grammarSource = _JChantGrammar.generateGrammar(ChantGrammarSyntax.CGSSAPI5XML);

// Compile a grammar
_JChantGrammar.compile(ChantGrammarSyntax.CGSSAPI5XML);

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

// Build Colors grammar
var wChantGrammar = WChantGM1.CreateGrammar("Colors");
wChantGrammar.AddComment("This is the list of colors");
var wChantGrammarRule = wChantGrammar.AddRule("Color");
var wChantGrammarList = wChantGrammarRule.AddList("colorlist");
wTChantGrammarList.AddPhrase("red");
wTChantGrammarList.AddPhrase("blue");
wTChantGrammarList.AddPhrase("green");
wTChantGrammarList.AddPhrase("yellow");
wTChantGrammarList.AddPhrase("pink");
wTChantGrammarList.AddPhrase("purple");
wTChantGrammarList.AddPhrase("brown");
wTChantGrammarList.AddPhrase("orange");

// Generate grammar source
var sGrammar = wChantGrammar.GenerateGrammar(CGSSAPI5XML);

// Compile a grammar file
WChantGM1.CompileResource(sGrammar, 0, CCOText, CGSSAPI5XML);

// Compile a grammar file and save results to file
WChantGM1.CompileResource(sGrammar, 0, CCOText, CGSSAPI5XML, "mygrammar.dat", CCRFile, 0, CCPAsynchronous);

Dim WithEvents XChantGM1 As XChantGM
Dim aXChantGrammar As XChantGrammar
Dim aXChantGrammarRule As XChantGrammarRule
Dim aXChantGrammarList As XChantGrammarList
Dim sGrammar As String

' Build Colors grammar
Set aXChantGrammar = XChantGM1.CreateGrammar("Colors")
aXChantGrammar.AddComment "This is the list of colors"
Set aXChantGrammarRule = aXChantGrammar.AddRule("Color")
Set aXChantGrammarList = aXChantGrammarRule.AddList("colorlist")
aXChantGrammarList.AddPhrase "red"
aXChantGrammarList.AddPhrase "blue"
aXChantGrammarList.AddPhrase "green"
aXChantGrammarList.AddPhrase "yellow"
aXChantGrammarList.AddPhrase "pink"
aXChantGrammarList.AddPhrase "purple"
aXChantGrammarList.AddPhrase "brown"
aXChantGrammarList.AddPhrase "orange"

' Generate grammar source
sGrammar = aXChantGrammar.GenerateGrammar(CGSSAPI5XML)

' Compile a grammar file
XChantGM1.CompileResource sGrammar, 0, CCOText, CGSSAPI5XML

' Compile a grammar file and save results to file
XChantGM1.CompileResource sGrammar, 0, CCOText, CGSSAPI5XML, "mygrammar.dat", CCRFile, 0, CCPAsynchronous

Dim WithEvents NChantGM1 As NChantGM
Dim _NChantGrammar As NChantGrammar
Dim nChantGrammarRule As NChantGrammarRule
Dim nChantGrammarList As NChantGrammarList
Dim grammarSource As String
' Instantiate ChantGM object
NChantGM1 = New NChantGM(Me)

' Build Colors grammar
_NChantGrammar = New NChantGrammar(NChantGM1, "Colors")
_NChantGrammar.AddComment("This is the list of colors")
nChantGrammarRule = _NChantGrammar.AddRule("Color")
nChantGrammarList = nChantGrammarRule.AddList("colorlist")
Dim colors() As String = { "red", "blue", "green", "yellow", "pink", "purple", "brown", "orange" }
nChantGrammarList.AddPhrases(colors);

' Generate grammar source
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();
        

// Define the vocabulary
CChantCommandVocab* pChantCommandVocab = new CChantCommandVocab(m_pChantSR, L"commands");

// Add commands to the vocabulary
pChantCommandVocab->AddCommand(L"Start Dictation");
pChantCommandVocab->AddCommand(L"Stop Dictation");
pChantCommandVocab->AddCommand(L"Show Dialog");

// Enable the vocabulary
pChantCommandVocab->Enable();

// Disable the vocabulary
pChantCommandVocab->Disable();
    

// Define the vocabulary
CChantCommandVocab* pChantCommandVocab = new CChantCommandVocab(ChantSR1, "commands");

// Add commands to the vocabulary
pChantCommandVocab->AddCommand("Start Dictation");
pChantCommandVocab->AddCommand("Stop Dictation");
pChantCommandVocab->AddCommand("Show Dialog");

// Enable the vocabulary
pChantCommandVocab->Enable();

// Disable the vocabulary
pChantCommandVocab->Disable();

var aTChantCommandVocab: TChantCommandVocab;
// Define the vocabulary
aTChantCommandVocab := TChantCommandVocab.Create(ChantSR1, 'commands');

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

// Enable the vocabulary
aTChantCommandVocab.Enable();

// Disable the vocabulary
aTChantCommandVocab.Disable();
    

// Define the vocabulary
JChantCommandVocab jChantCommandVocab = new JChantCommandVocab(JChantSR1, "commands");

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

// Enable the vocabulary
jChantCommandVocab.enable();

// Disable the vocabulary
jChantCommandVocab.disable();
    

// Define a command vocabulary
var CommandVocabID = WChantSR1.DefineResource(CSRCommandVocab, "commands");

// Add commands to the vocabulary
WChantSR1.AddResource(CSRVocabPhrase,CommandVocabID,"Start Dictation");
WChantSR1.AddResource(CSRVocabPhrase,CommandVocabID,"Stop Dictation");
WChantSR1.AddResource(CSRVocabPhrase,CommandVocabID,"Show Dialog");

// Enable command vocabulary
WChantSR1.EnableResource(CSRCommandVocab, CommandVocabID);

// Disable the vocabulary
WChantSR1.DisableResource(CSRCommandVocab, CommandVocabID);

Dim CommandVocabID As Integer
' Define a command vocabulary
CommandVocabID = XChantSR1.DefineResource(CSRCommandVocab, "commands")

' Add commands to the vocabulary
XChantSR1.AddResource CSRVocabPhrase, CommandVocabID, "Start Dictation"
XChantSR1.AddResource CSRVocabPhrase, CommandVocabID, "Stop Dictation"
XChantSR1.AddResource CSRVocabPhrase, CommandVocabID, "Show Dialog"

' Enable command vocabulary
XChantSR1.EnableResource CSRCommandVocab, CommandVocabID

' Disable command vocabulary
XChantSR1.DisableResource CSRCommandVocab, CommandVocabID

' Define the vocabulary
Dim nChantCommandVocab As 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();
        

    
// Define general navigation commands for use with list box and combo box // These are generic key input simulations // VK_UP x26 CChantSRCommand* pSelectPreviousCmd = new CChantSRCommand(m_pChantSR, L"select previous", CRFKeyInput, 0, 0, 0x26); // VK_DOWN x28 CChantSRCommand* pSelectNextCmd = new CChantSRCommand(m_pChantSR, L"select next", CRFKeyInput, 0, 0, 0x28); // Enable the voice commands pSelectPreviousCmd->Enable(); pSelectNextCmd->Enable(); // Disable the voice commands pSelectPreviousCmd->Disable(); pSelectNextCmd->Disable();

// Define general navigation commands for use with list box and combo box
// These are generic key input simulations
// VK_UP x26
CChantSRCommand* pSelectPreviousCmd = new CChantSRCommand(ChantSR1, "select previous", CRFKeyInput, 0, 0, 0x26);

// VK_DOWN x28
CChantSRCommand* pSelectNextCmd = new CChantSRCommand(ChantSR1, "select next", CRFKeyInput, 0, 0, 0x28);

// Enable the voice commands
pSelectPreviousCmd->Enable();
pSelectNextCmd->Enable();

// Disable the voice commands
pSelectPreviousCmd->Disable();
pSelectNextCmd->Disable();

var  selectPreviousCmd, selectNextCmd: TChantSRCommand;
// Define general navigation commands for use with list box and combo box
// These are generic key input simulations
// VK_UP x26
selectPreviousCmd := TChantSRCommand.Create(ChantSR1, 'select previous', CRFKeyInput, 0, 0, $26);

// VK_DOWN x28
selectNextCmd := TChantSRCommand.Create(ChantSR1, 'select next', CRFKeyInput, 0, 0, $28);

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

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

// Define general navigation commands for use with list box and combo box
// These are generic key input simulations
// VK_UP x26
JChantSRCommand jSelectPreviousCmd = new JChantSRCommand(JChantSR1, "select previous", CRFKeyInput, 0, 0, 0x26);

// VK_DOWN x28
JChantSRCommand jSelectNextCmd = new JChantSRCommand(JChantSR1, "select next", CRFKeyInput, 0, 0, 0x28);

// Enable the voice commands
jSelectPreviousCmd.enable();
jSelectNextCmd.enable();

// Disable the voice commands
jSelectPreviousCmd.disable();
jSelectNextCmd.disable();
    

// Simulate an enter key: VK_RETURN X0D 
var selectCmdID = document.WChantSR1.DefineResource(CSRCommand, "press enter key", CRFKeyInput, 0, 0, 0x0D, 0);
// Enable the resource to make them active
WChantSR1.EnableResource(CSRCommand, selectCmdID);
// Disable it
WChantSR1.DisableResource(CSRCommand, selectCmdID);

// Simulate an ALT+Down key: VK_MENU X13 (ALT) + VK_DOWN x28
var dropDownCmdID = document.WChantSR1.DefineResource(CSRCommand, "drop down", CRFKeyInputAlt, 0, 0, 0x28, 0)
// Enable the resource to make them active
WChantSR1.EnableResource(CSRCommand, dropDownCmdID);
// Disable it
WChantSR1.DisableResource(CSRCommand, dropDownCmdID);

Dim selectCmdID, dropDownCmdID As Integer
' Simulate an enter key: VK_RETURN X0D 
selectCmdID = XChantSR1.DefineResource(CSRCommand, "press enter key", CRFKeyInput, 0, 0, 0x0D, 0)
' Enable the resource to make them active
XChantSR1.EnableResource CSRCommand, selectCmdID
' Disable it
XChantSR1.DisableResource CSRCommand, selectCmdID

' Simulate an ALT+Down key: VK_MENU X13 (ALT) + VK_DOWN x28
dropDownCmdID = XChantSR1.DefineResource(CSRCommand, "drop down", CRFKeyInputAlt, 0, 0, 0x28, 0)
' Enable the resource to make them active
XChantSR1.EnableResource CSRCommand, dropDownCmdID
' Disable it
XChantSR1.DisableResource CSRCommand, dropDownCmdID

' Define general navigation commands for use with list box and combo box
' These are generic key input simulations
' VK_UP x26
Dim selectPreviousCmd As NChantSRCommand
selectPreviousCmd = New NChantSRCommand(NChantSR1, "select previous", ChantResourceFunction.CRFKeyInput, Nothing, Nothing, &H26)
' VK_DOWN x28
Dim selectNextCmd As NChantSRCommand
selectNextCmd = New NChantSRCommand(NChantSR1, "select next", ChantResourceFunction.CRFKeyInput, Nothing, Nothing, &H28)

' Enable the voice commands
selectPreviousCmd.Enable()
selectNextCmd.Enable()

' Disable the voice commands
selectPreviousCmd.Disable()
selectNextCmd.Disable()