Choices Class

Represents a list of alternative items to make up an element in a grammar.

Inheritance Hierarchy


Namespace:  Microsoft.Speech.Recognition
Assembly:  Microsoft.Speech (in Microsoft.Speech.dll)


Public Class Choices
Dim instance As Choices
public class Choices


A Choices object represents a component of a phrase that can have one of several values. Use this class when creating a speech recognition grammar from a GrammarBuilder object.

For example, a Choices object could represent the component colorChoice in the phrase, "Change the color to colorChoice", where acceptable values for colorChoice are “red”, or “green”, or “blue”.


To use a Choices object as an optional component in a phrase, create the Choices object and add it to a GrammarBuilder.GrammarBuilder(GrammarBuilder, Int32, Int32) object with minRepeat and maxRepeat set to 0 and 1, respectively. Phrases containing optional components can be recognized whether or not the optional component is spoken.

The Choices class serves the same function as the one-of XML element defined by the Speech Recognition Grammar Specification (SRGS) Version 1.0, and is similar to the SrgsOneOf class in the Microsoft.Speech.Recognition.SrgsGrammar namespace.


The following example creates a speech recognition grammar for the phrase, "Set background to colorChoice", where colorChoice can be one of the defined colors. The GrammarBuilder is used to define the constraints for the grammar.

private Grammar CreateColorGrammar()

  // Create a Choices object that contains a set of alternative colors.
  Choices colorChoice = new Choices(new string[] {"red", "green", "blue"});
  colorChoice.Add(new string[] {"cyan", "yellow", "magenta"});

  // Construct the phrase.
  GrammarBuilder builder = new GrammarBuilder("Set background to");

  // Create a grammar for the phrase.
  Grammar colorGrammar = new Grammar(builder);
  colorGrammar.Name = "SetBackground";

  return colorGrammar;

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also


Choices Members

Microsoft.Speech.Recognition Namespace




Other Resources

Speech Recognition Grammar Specification (SRGS) Version 1.0