GrammarBuilder.Addition Operator

Definition

Creates a new GrammarBuilder that corresponds to a sequence of two grammar elements.

Overloads

Addition(Choices, GrammarBuilder)

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

Addition(GrammarBuilder, Choices)

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

Addition(GrammarBuilder, GrammarBuilder)

Creates a new GrammarBuilder that contains a sequence of two GrammarBuilder objects.

Addition(GrammarBuilder, String)

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

Addition(String, GrammarBuilder)

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

Remarks

The order of the operands determines the order of the elements in the new GrammarBuilder.

Important

Caution is recommended when combining Choices or GrammarBuilder objects that contain SemanticResultValue or SemanticResultKey instances with other grammar elements. The speech recognizer can throw an exception when using a speech recognition grammar that contains duplicate semantic elements with the same key name or multiple semantic elements that could repeatedly modify the value of the same semantic element.

For more information about building and using speech recognition grammars, see Speech Recognition.

Addition(Choices, GrammarBuilder)

Source:
GrammarBuilder.cs
Source:
GrammarBuilder.cs
Source:
GrammarBuilder.cs

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

C#
public static System.Speech.Recognition.GrammarBuilder operator +(System.Speech.Recognition.Choices choices, System.Speech.Recognition.GrammarBuilder builder);

Parameters

choices
Choices

The first grammar element, which represents a set of alternatives.

builder
GrammarBuilder

The second grammar element.

Returns

Returns a GrammarBuilder for the sequence of the choices parameter followed by the builder parameter.

Remarks

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

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.

The equivalent method for this operator is GrammarBuilder.Add(Choices, GrammarBuilder)

See also

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)

Addition(GrammarBuilder, Choices)

Source:
GrammarBuilder.cs
Source:
GrammarBuilder.cs
Source:
GrammarBuilder.cs

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

C#
public static System.Speech.Recognition.GrammarBuilder operator +(System.Speech.Recognition.GrammarBuilder builder, System.Speech.Recognition.Choices choices);

Parameters

builder
GrammarBuilder

The first grammar element.

choices
Choices

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

Returns

Returns a GrammarBuilder for the sequence of the builder parameter followed by the choices parameter.

Examples

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.

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

Remarks

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

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.

The equivalent method for this operator is GrammarBuilder.Add(GrammarBuilder, Choices)

See also

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)

Addition(GrammarBuilder, GrammarBuilder)

Source:
GrammarBuilder.cs
Source:
GrammarBuilder.cs
Source:
GrammarBuilder.cs

Creates a new GrammarBuilder that contains a sequence of two GrammarBuilder objects.

C#
public static System.Speech.Recognition.GrammarBuilder operator +(System.Speech.Recognition.GrammarBuilder builder1, System.Speech.Recognition.GrammarBuilder builder2);

Parameters

builder1
GrammarBuilder

The first grammar element.

builder2
GrammarBuilder

The second grammar element.

Returns

Returns a GrammarBuilder for the sequence of the builder1 parameter followed by the builder2 parameter.

Remarks

GrammarBuilder supports conversions from the following classes.

This method accepts the objects listed above for the builder1 and builder2 parameters. For more information, see the Implicit operators.

Important

When you combine 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.

The equivalent method for this operator is GrammarBuilder.Add(GrammarBuilder, GrammarBuilder)

See also

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)

Addition(GrammarBuilder, String)

Source:
GrammarBuilder.cs
Source:
GrammarBuilder.cs
Source:
GrammarBuilder.cs

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

C#
public static System.Speech.Recognition.GrammarBuilder operator +(System.Speech.Recognition.GrammarBuilder builder, string phrase);

Parameters

builder
GrammarBuilder

The first grammar element.

phrase
String

The second grammar element, which represents a sequence of words.

Returns

Returns a GrammarBuilder for the sequence of the builder parameter followed by the phrase parameter.

Remarks

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.

The equivalent method for this operator is GrammarBuilder.Add(GrammarBuilder, String)

See also

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)

Addition(String, GrammarBuilder)

Source:
GrammarBuilder.cs
Source:
GrammarBuilder.cs
Source:
GrammarBuilder.cs

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

C#
public static System.Speech.Recognition.GrammarBuilder operator +(string phrase, System.Speech.Recognition.GrammarBuilder builder);

Parameters

phrase
String

The first grammar element, which represents a sequence of words.

builder
GrammarBuilder

The second grammar element.

Returns

Returns a GrammarBuilder for the sequence of the phrase parameter followed by the builder parameter.

Examples

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.

C#
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 object 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;
}

Remarks

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.

The equivalent method for this operator is GrammarBuilder.Add(String, GrammarBuilder)

See also

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)