How do I manage listening context with speech recognition vocabularies?

Last reviewed: 7/8/2021

HOW Article ID: H072103

The information in this article applies to:

  • SpeechKit 10

Summary

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
_CommandVocab.Enable();

// Disable the vocabulary
_CommandVocab.Disable();

// Define the vocabulary
CChantCommandVocab* _CommandVocab = _Recognizer->CreateCommandVocab(L"commands");

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

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

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

// Define the vocabulary
CChantCommandVocab* _CommandVocab = _Recognizer->CreateCommandVocab("commands");

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

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

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

var _CommandVocab: TChantCommandVocab;
// Define the vocabulary
_CommandVocab := _Recognizer.CreateCommandVocab('commands');

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

// Enable the vocabulary
_CommandVocab.Enable();

// Disable the vocabulary
_CommandVocab.Disable();
    

// Define the vocabulary
JChantCommandVocab _CommandVocab = _Recognizer.createCommandVocab("commands");

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

// Enable the vocabulary
_CommandVocab.enable();

// Disable the vocabulary
_CommandVocab.disable();
    

' Define the vocabulary
Dim _CommandVocab As 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
_CommandVocab.Enable()

' Disable the vocabulary
_CommandVocab.Disable()

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
W3C SRGS XML
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
_GrammarVocab.Enable();

// Disable the vocabulary
_GrammarVocab.Disable();

// Define the vocabulary
CChantGrammarVocab* _GrammarVocab = _Recognizer->CreateGrammarVocab(L"mygrammar.xml");

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

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

// Define the vocabulary
CChantGrammarVocab* _GrammarVocab = _Recognizer->CreateGrammarVocab("mygrammar.xml");

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

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

var _GrammarVocab: TChantGrammarVocab;
// Define the vocabulary
_GrammarVocab := _Recognizer.CreateGrammarVocab('mygrammar.xml');

// Enable the vocabulary
_GrammarVocab.Enable();

// Disable the vocabulary
_GrammarVocab.Disable();

// Define the vocabulary
JChantGrammarVocab _GrammarVocab = _Recognizer.createGrammarVocab("mygrammar.xml");

// Enable the vocabulary
_GrammarVocab.enable();

// Disable the vocabulary
_GrammarVocab.disable();

' Define the vocabulary
Dim _GrammarVocab As NChantGrammarVocab
_GrammarVocab = _Recognizer.CreateGrammarVocab("mygrammar.xml")

' Enable the vocabulary
_GrammarVocab.Enable()

' Disable the vocabulary
_GrammarVocab.Disable()

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
_DictationVocab.Enable();

// Disable the vocabulary
_DictationVocab.Disable();

// Define the vocabulary
CChantDictationVocab* _DictationVocab = _Recognizer->CreateDictationVocab(L"text");

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

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

// Define the vocabulary
CChantDictationVocab* _DictationVocab = _Recognizer->CreateDictationVocab("text");

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

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

var _DictationVocab: TChantDictationVocab;
// Define the vocabulary
_DictationVocab := _Recognizer.CreateDictationVocab('text');

// Enable the vocabulary
aTChantDictationVocab.Enable();

// Disable the vocabulary
aTChantDictationVocab.Disable();

// Define the vocabulary
JChantDictationVocab _DictationVocab = _Recognizer.createDictationVocab("text");

// Enable the vocabulary
_DictationVocab.enable();

// Disable the vocabulary
_DictationVocab.disable();

' Define the vocabulary
Dim _DictationVocab As NChantDictationVocab
_DictationVocab = _Recognizer.CreateDictationVocab("text")

' Enable the vocabulary
_DictationVocab.Enable()

' Disable the vocabulary
_DictationVocab.Disable()

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
_DictationVocab.Enable();

// Disable the vocabulary
_DictationVocab.Disable();

// Define the vocabulary
CChantDictationVocab* _DictationVocab = _Recognizer->CreateDictationVocab(L"Spelling");

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

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

// Define the vocabulary
CChantDictationVocab* _DictationVocab = _Recognizer->CreateDictationVocab("Spelling");

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

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

var _DictationVocab: TChantDictationVocab;
// Define the vocabulary
_DictationVocab := _Recognizer.CreateDictationVocab('Spelling');

// Enable the vocabulary
_DictationVocab.Enable();

// Disable the vocabulary
_DictationVocab.Disable();
    

// Define the vocabulary
JChantDictationVocab _DictationVocab = _Recognizer.createDictationVocab("Spelling");

// Enable the vocabulary
_DictationVocab.enable();

// Disable the vocabulary
_DictationVocab.disable();

' Define the vocabulary
Dim _DictationVocab As NChantDictationVocab
_DictationVocab = _Recognizer.CreateDictationVocab("Spelling")

' Enable the vocabulary
_DictationVocab.Enable()

' Disable the vocabulary
_DictationVocab.Disable()