Last reviewed: 3/23/2024 10:09:27 AM

Vocabularies

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.

For Windows desktop applications, 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.

For Android, iOS, and macOS applications, speech recognition does not begin until StartRecognition is invoked and stopped automatically when either and utterance is recognized or a timeout exception occurs except when using a dictation vocabulary. With a dictation vocabulary, speech recognition is automatically restarted after an utterance is recognized or a timeout exception occurs until it is 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.

For Android, iOS, and macOS applications, the RecognitionOther event is fired if there is no command vocabulary match for recognized speech.

To test command vocabularies in the Chant Developer Workbench, create a text file for each vocabulary containing a phrase on each line. Property values are separated by a comma:

red, 1
blue, 2
green, 3
orange, 4
purple, 5
yellow, 6
brown, 7
black, 8
white, 9

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


// Define the vocabulary
JChantCommandVocab _CommandVocab = _Recognizer.createCommandVocab("commands");
// Add commands to the vocabulary
_CommandVocab.addCommand("Open <filename>");
_CommandVocab.addCommand("Print <filename>");
_CommandVocab.addCommand("Close <filename>");
// Add choices to list
_CommandVocab.addChoiceToList("expenses", "filename");
_CommandVocab.addChoiceToList("status report", "filename");
// Enable the vocabulary
_CommandVocab.enable();
// Disable the vocabulary
_CommandVocab.disable();

// 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();

@property (strong, nonatomic) SPChantCommandVocab* commandVocab;
// Define the vocabulary
_commandVocab = [_recognizer createCommandVocab:@"commands"];
// Add commands to the vocabulary
[_commandVocab addCommand:@"Open &lt;filename&gt;"];
[_commandVocab addCommand:@"Print &lt;filename&gt;"];
[_commandVocab addCommand:@"Close &lt;filename&gt;"];
// Add choices to list
[_commandVocab addChoiceToList:@"expenses" listName:@"filename"];
[_commandVocab addChoiceToList:@"status report" listName:@"filename"];
// Enable the vocabulary
[_commandVocab enable];
// Disable the vocabulary
[_commandVocab disable];

var _CommandVocab: SPChantCommandVocab? = nil
// Define the vocabulary
_CommandVocab = _Recognizer.createCommandVocab(name:"commands")
// Add commands to the vocabulary
_CommandVocab!.addCommand(command:"Open <filename>")
_CommandVocab!.addCommand(command:"Print <filename>")
_CommandVocab!.addCommand(command:"Close <filename>")
// Add choices to list
_CommandVocab!.addChoiceToList(choice:"expenses", listName:"filename")
_CommandVocab!.addChoiceToList(choice:"status report", listName:"filename")
// 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 WindowsMedia (all languages)WindowsMediaW3C SRGS XML

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


// Not supported on Android
    

// 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();
    

// Not supported on iOS and macOS
    

// Not supported on iOS and macOS
    

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

See GrammarKit for more information about speech recognition grammars.

Semantic Interpretation Markup

Semantic interpretation markup extends the rule matching process used by a recognizer in formulating speech recognition results.

Applications may use semantic data from rule matches to facilitate processing speech recognition results returned by the speech recognizer.

The tag-format attribute of the grammar element identifies the type of semantic interpretation markup in the tag element CDATA. For grammars used with Microsoft speech recognition engines, this value can be: semantics/1.0, semantics-ms/1.0, or properties-ms/1.0.

The Grammar Recognition sample illustrates using semantic properties to select the listbox item based on recognition matches. The commands.grxml uses the tag format properties-ms/1.0 to return a rule identifier and list choice identifier.

The Command Recognition sample illustrates achieving the same semantic interpretation with dynamic declarations.

Review the Microsoft Learn topic on Semantic Interpretation Markup to explore the power possible with the tag element.

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
JChantDictationVocab _DictationVocab = _Recognizer.createDictationVocab("text");
// Enable the vocabulary
_DictationVocab.enable();
// Disable the vocabulary
_DictationVocab.disable();

// 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();

@property (strong, nonatomic) SPChantDictationVocab* dictationVocab;
// Define the vocabulary
_dictationVocab = [_recognizer createDictationVocab:@"text"];
// Enable the vocabulary
[_commandVocab enable];
// Disable the vocabulary
[_commandVocab disable];

var _DictationVocab: SPChantDictationVocab? = nil
// Define the vocabulary
_DictationVocab = _Recognizer.createDictationVocab(name:"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.

Dragon NaturallySpeaking may support topics Numbers and Letters (for spelling).

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


// Not supported on Android

// 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();

// Not supported on iOS and macOS

// Not supported on iOS and macOS

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