Share via


Note

Please see Azure Cognitive Services for Speech documentation for the latest supported speech solutions.

Choices.Add Method (GrammarBuilder[])

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

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

Syntax

'Declaration
Public Sub Add ( _
    ParamArray alternateChoices As GrammarBuilder() _
)
'Usage
Dim instance As Choices
Dim alternateChoices As GrammarBuilder()

instance.Add(alternateChoices)
public void Add(
    params GrammarBuilder[] alternateChoices
)

Parameters

Remarks

Because of support for implicit conversion from Choices, SemanticResultKey, and SemanticResultValue objects to GrammarBuilder, these three classes may be added to a Choices instance as well.

If alternateChoices is an empty array, this method does not update the set of alternatives.

Applications can use both Add([]) and Add([]) to add alternatives to a Choices object.

This method throws an ArgumentNullException when alternateChoices is a null reference (Nothing in Visual Basic) or any of the array elements are a null reference (Nothing in Visual Basic).

Examples

The following example creates a speech recognition grammar for phrases such as "Call Anne on her cell" and "Call James on his work phone". The example uses both overloads of the Add method to build the grammar.

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

Reference

Choices Class

Choices Members

Add Overload

Microsoft.Speech.Recognition Namespace

GrammarBuilder

Grammar