שתף באמצעות


Choices Class

Definition

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

public ref class Choices
public class Choices
type Choices = class
Public Class Choices
Inheritance
Choices

Examples

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

Remarks

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".

Note

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.

Constructors

Choices()

Initializes a new instance of the Choices class that contains an empty set of alternatives.

Choices(GrammarBuilder[])

Initializes a new instance of the Choices class from an array containing one or more GrammarBuilder objects.

Choices(String[])

Initializes a new instance of the Choices class from an array containing one or more String objects.

Methods

Add(GrammarBuilder[])

Adds an array containing one or more GrammarBuilder objects to the set of alternatives.

Add(String[])

Adds an array containing one or more String objects to the set of alternatives.

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToGrammarBuilder()

Returns a GrammarBuilder object from this Choices object.

ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to

See also