Addition Operator (String, GrammarBuilder)

Microsoft Speech Platform SDK 11

Collapse imageExpand ImageCopy imageCopyHover image

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

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

Syntax

Visual Basic (Declaration)
Public Shared Operator + ( _
	phrase As String, _
	builder As GrammarBuilder _
) As GrammarBuilder
Visual Basic (Usage)
Dim phrase As String
Dim builder As GrammarBuilder
Dim returnValue As GrammarBuilder

returnValue = (phrase + builder)
C#
public static GrammarBuilder operator +(
	string phrase,
	GrammarBuilder builder
)

Parameters

phrase
Type: System..::..String

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

builder
Type: Microsoft.Speech.Recognition..::..GrammarBuilder

The second grammar element.

Return Value

Type: Microsoft.Speech.Recognition..::..GrammarBuilder

Returns a GrammarBuilder for the sequence of the phrase 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 ImplicitWideningImplicitImplicitImplicit operators.

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

See Also