Choices Constructor (GrammarBuilder[])

Microsoft Speech Platform SDK 11

Collapse imageExpand ImageCopy imageCopyHover image

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

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

Syntax

Visual Basic (Declaration)
Public Sub New ( _
	ParamArray alternateChoices As GrammarBuilder() _
)
Visual Basic (Usage)
Dim alternateChoices As GrammarBuilder()

Dim instance As New Choices(alternateChoices)
C#
public Choices(
	params GrammarBuilder[] alternateChoices
)

Parameters

alternateChoices
Type: array<Microsoft.Speech.Recognition..::..GrammarBuilder>[]()[][]

An array containing the set of alternatives.

Remarks

Each GrammarBuilder in alternateChoices defines one alternative. If alternateChoices is an empty array, the constructor returns an empty set of alternatives. You can add alternatives using any of the Add methods.

The constructor throws an ArgumentNullException when alternateChoices is nullNothingnullptrunita null reference (Nothing in Visual Basic) or when any of the array elements are nullNothingnullptrunita null reference (Nothing in Visual Basic).

Because the GrammarBuilder class provides support for implicit conversion of Choices, SemanticResultValue, and SemanticResultKey objects to GrammarBuilder instances, by properly using casts, this constructor can also be used to create a Choices object from a list of any combination of these objects.

Examples

The following example uses Choices and GrammarBuilder objects 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.

 Copy imageCopy Code
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);
}

See Also