How Tos

Last reviewed: 7/8/2021

Article ID: H072103

HOW: Managing listening context with speech recognition vocabularies

The information in this article applies to:

  • SpeechKit 10


Explore the new way of managing listening context with speech recognition vocabularies.

More Information

Vocabularies define the listening context from which to recognize speech. Speech recognition engines may support four types of vocabularies:

  • command,
  • grammar,
  • dictation, and
  • dictation topic.

To recognize speech with vocabularies, applications define the vocabulary, enable it to make it active, and disable it to make it inactive.

Applications can instantiate, enable, and disable vocabularies as needed to manage the listening context. More than one vocabulary may be enabled concurrently.

Speech recognition does not begin until StartRecognition is invoked and stopped when StopRecognition is invoked. Disabling a vocabulary during recognition has no effect. Speech recognition must be stopped before changing the listening context by enabling and disabling vocabularies.

Command Vocabulary

A command vocabulary consists of words and phrases that are spoken as commands. It is a simple list of the possible spoken words and phrases. The speech recognition engine matches recognized speech against the list and returns the best match. Command vocabularies are typically very small. For example, a command vocabulary may contain a 100 or fewer entries.

A command phrase can optionally have a property value associated with it. This enables processing recognition results on the basis of alternate values in addition to command strings.

To create a command vocabulary, instantiate a ChantCommandVocab class object. Then add the commands.

// Define the vocabulary
NChantCommandVocab _CommandVocab = _Recognizer.CreateCommandVocab("commands");

// Add commands to the vocabulary
_CommandVocab.AddCommand("Open File");
_CommandVocab.AddCommand("Print File");
_CommandVocab.AddCommand("Close File");

// Enable the vocabulary

// Disable the vocabulary

Grammar Vocabulary

A grammar vocabulary consists of words and phrases and combinations of words and phrases expressed in a grammar syntax. Recognizers have their own syntax for expressing grammars.

Recognizer Speech API Grammar Syntax
Microsoft SAPI 5 (all languages)SAPI 5SAPI 5 XML Grammar
Microsoft Speech Platform (all languages)SAPI 5W3C SRGS XML
Microsoft .NET System.Speech (all languages)System.SpeechW3C SRGS XML
Microsoft .NET Microsoft.Speech (all languages)Microsoft.SpeechW3C SRGS XML
Microsoft WindowsMedia (UWP and WinRT) (all languages)WindowsMediaW3C SRGS XML

To create a grammar vocabulary from a grammar source file, use the ChantGrammarVocab class.

// Define the vocabulary
NChantGrammarVocab _GrammarVocab = _Recognizer.CreateGrammarVocab("mygrammar.xml");

// Enable the vocabulary

// Disable the vocabulary

Dictation Vocabulary

A dictation vocabulary represents a dictionary of all possible words from which speech is recognized. These vocabularies are integrated with the speech recognition engine. They are typically very large. For example, a dictionary may contain 30,000 and significantly more words.

To create a dictation vocabulary, use the ChantDictationVocab class.

// Define the vocabulary
NChantDictationVocab _DictationVocab = _Recognizer.CreateDictationVocab("text");

// Enable the vocabulary

// Disable the vocabulary

SAPI5 currently defines one specialized dictation topic: Spelling. SAPI5 recognition engines are not required to support specialized dictation topics including Spelling.

To enable a topic with SAPI5, use the ChantDictationVocab class and specify the topic name.

// Define the vocabulary
NChantDictationVocab _DictationVocab = _Recognizer.CreateDictationVocab("Spelling");

// Enable the vocabulary

// Disable the vocabulary