GrammarBuilder Constructor (String)

Microsoft Speech Platform SDK 11

Collapse image Expand Image Copy image CopyHover image

Initializes a new instance of the GrammarBuilder class from a sequence of words.

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

Syntax

Visual Basic (Declaration)
Public Sub New ( _
	phrase As String _
)
Visual Basic (Usage)
Dim phrase As String

Dim instance As New GrammarBuilder(phrase)
C#
public GrammarBuilder(
	string phrase
)

Parameters

phrase
Type: System..::..String

The sequence of words.

Remarks

The phrase represents an exact spoken phrase that the speech recognition grammar can recognize. For more information about building a speech recognition grammar that contains strings, see Use a String to Create a GrammarBuilder (Microsoft.Speech).

Examples

The following example uses GrammarBuilder and Choices objects to construct a grammar that can recognize either of the two phrases, "Make background colorChoice" or "Set background to colorChoice".

After creating a list of acceptable values for colorChoice using a Choices object, the example initializes two GrammarBuilder objects, makePhrase and setPhrase, using a string as an argument.

The example finally creates a Grammar object from a GrammarBuilder constructed from a Choices object.

C# Copy imageCopy Code
private Grammar CreateColorGrammar()
{

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

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

  // 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});
  Grammar grammar = new Grammar((GrammarBuilder)bothChoices);
  grammar.Name = "backgroundColor";
  return grammar;
}

See Also