Export (0) Print
Expand All

GrammarBuilder.Addition Operator (GrammarBuilder, Choices)

Creates a new GrammarBuilder that contains a GrammarBuilder followed by a Choices.

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

public static GrammarBuilder operator +(
	GrammarBuilder builder,
	Choices choices
)

Parameters

builder
Type: System.Speech.Recognition.GrammarBuilder

The first grammar element.

choices
Type: System.Speech.Recognition.Choices

The second grammar element, which represents a set of alternative elements.

Return Value

Type: System.Speech.Recognition.GrammarBuilder
Returns a GrammarBuilder for the sequence of the builder parameter followed by the choices parameter.

GrammarBuilder supports conversions from the following classes:

This method accepts the objects listed above for the builder parameter. For more information, see the Implicit operators.

Important noteImportant

When you combine Choices and GrammarBuilder objects that contain SemanticResultValue or SemanticResultKey instances, make sure you avoid creating duplicate semantic elements with the same key name or multiple semantic elements that could repeatedly modify the Value property of a SemanticValue object. The speech recognizer can throw an exception if it encounters these circumstances. For more information about building a speech recognition grammar that contains semantic information, see Understanding SemanticResultValue and SemanticResultKey Objects.

The following example creates a speech recognition grammar that can recognize the two phrases, "Make background color" and "Set background to color", where color is selected from a set of colors. Various types are used to build the final grammar, such as String, Choices, and GrammarBuilder objects.

private Grammar CreateColorGrammar()
{

  // Create a set of color choices.
  Choices colorChoice = new Choices(new string[] { "red", "green", "blue" });

  // Create grammar builders for the two versions of the phrase.
  GrammarBuilder makePhrase =
    (GrammarBuilder)"Make background" + colorChoice;
  GrammarBuilder setPhrase =
    "Set background to" + (GrammarBuilder)colorChoice;

  // Create a Choices for the two alternative phrases, convert the Choices
  // to a GrammarBuilder, and construct the grammar from the result.
  Choices bothChoices = new Choices(new GrammarBuilder[] { makePhrase, setPhrase });
  GrammarBuilder bothPhrases = new GrammarBuilder(bothChoices);

  Grammar grammar = new Grammar(bothPhrases);
  grammar.Name = "backgroundColor";
  return grammar;
}

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

Show:
© 2014 Microsoft