Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Choices Class

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

System.Object
  Microsoft.Speech.Recognition.Choices

Namespace:  Microsoft.Speech.Recognition
Assembly:  Microsoft.Speech (in Microsoft.Speech.dll)
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”.

NoteNote

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");
  builder.Append(colorChoice);

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

  return colorGrammar;
}
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.