Choices Constructor ()

 

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

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

public:
Choices()

This constructor returns a valid, empty set of alternatives. You can add alternatives using any of the Add methods.

The following example uses Choices and GrammarBuilderobjects to create a phrase that can be used to recognize speech input such as "Call Anne on her cell" and "Call James on his work phone". The example uses implicit casts from Choices and String to GrammarBuilder.

public Grammar CreatePhonePhrase()
{

  // Create alternatives for female names and add a phrase.
  GrammarBuilder females = new Choices(new string[] { "Anne", "Mary" });
  females.Append("on her");

  // Create alternatives for male names and add a phrase.
  GrammarBuilder males = new Choices(new string[] { "James", "Sam" });
  males.Append("on his");

  // Create a Choices object that contains an array of alternative
  // GrammarBuilder objects.
  Choices people = new Choices();
  people.Add(new Choices(new GrammarBuilder[] {females, males}));

  // Create a Choices object that contains a set of alternative phone types.
  Choices phoneType = new Choices();
  phoneType.Add(new string[] { "cell", "home", "work" });

  // Construct the phrase.
  GrammarBuilder gb = new GrammarBuilder();
  gb.Append("call");
  gb.Append(people);
  gb.Append(phoneType);
  gb.Append(new GrammarBuilder("phone"), 0, 1);

  return new Grammar(gb);
}

.NET Framework
Available since 3.0
Return to top
Show: