Export (0) Print
Expand All

Choices Class

Represents a set of alternatives in the constraints of a speech recognition grammar.

System.Object
  System.Speech.Recognition.Choices

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

public class Choices

The Choices type exposes the following members.

  NameDescription
Public methodChoices()Initializes a new instance of the Choices class that contains an empty set of alternatives.
Public methodChoices(GrammarBuilder[])Initializes a new instance of the Choices class from an array containing one or more GrammarBuilder objects.
Public methodChoices(String[])Initializes a new instance of the Choices class from an array containing one or more String objects.
Top

  NameDescription
Public methodAdd(GrammarBuilder[])Adds an array containing one or more GrammarBuilder objects to the set of alternatives.
Public methodAdd(String[])Adds an array containing one or more String objects to the set of alternatives.
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToGrammarBuilderReturns a GrammarBuilder object from this Choices object.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

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 System.Speech.Recognition.SrgsGrammar namespace.

For more information about defining a speech recognition grammar, see Speech Recognition and Creating GrammarBuilder Grammars.

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;
}

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

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