Determining dynamic grammar list enablement state

Last reviewed: 9/10/2008

HOW Article ID: H090806

The information in this article applies to:

  • SpeechKit 6


SpeechKit vocabulary management supports enabling and disabling of word lists within grammars with the EnableResource and DisableResource methods.

Grammar word lists provide a way to substitute choices within the context of a grammar rule. With SpeechKit 6, grammar list enablement state can be obtained via its resource identifier and the Chant IsResourceEnabled method. In addition, disabling the grammar automatically disables the list resource.

More Information

Word lists enable you to substitute a list of words or phrases at runtime. You define a word list using the DefineResource method with the CSRVocabList speech resource using the vocabulary resource id with which it is associated. Then you add the words to the list using the ChantSR AddResource method with the CSRVocabPhrase speech resource. You set the list active by enabling it with EnableResource and inactive by disabling it with DisableResource.

With SpeechKit 6, you now have the ability to use the ChantSR IsResourceEnabled method to determine the enable state of the list. Disabling the list is no longer required and will automatically happen when the grammar is disabled.

The following example illustrates defining, enabling, and disable word lists:

// For Microsoft SAPI 4 Grammar Text File
VocabID = ChantSR.DefineResource(CSRGrammarVocab, "c:\\myvocab.cfg")
// For Microsoft SAPI 5 XML Grammar
VocabID = ChantSR.DefineResource(CSRGrammarVocab, "c:\\myvocab.xml")
// For Nuance VoCon 3200 BNF+ Grammar
VocabID = ChantSR.DefineResource(CSRGrammarVocab, "c:\\myvocab.bnf")
ListID = ChantSR.DefineResource(CSRVocabList, "rulelistname", CRFNone, NULL, NULL, 0, VocabID)
ChantSR.AddResource(CSRVocabPhrase, ListID, "Log Call")
ChantSR.AddResource(CSRVocabPhrase, ListID, "Enter Time")
ChantSR.AddResource(CSRVocabPhrase, ListID, "Schedule Meeting")
// Enable the word list
ChantSR.EnableResource(CSRGrammarVocab, VocabID)
ChantSR.EnableResource(CSRVocabList, ListID)

// Is the list enabled?
if (ChantSR.IsResourceEnabled(CSRVocabList, ListID))
  // Yes, then Disable the list
  ChantSR.DisableResource(CSRVocabList, ListID))

// In SpeechKit 6, the list automatically disabled when disabling the vocabulary
ChantSR.DisableResource(CSRGrammarVocab, VocabID)