Note

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

GrammarBuilder Constructor (String)

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

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

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

Parameters

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.

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

Reference

GrammarBuilder Class

GrammarBuilder Members

GrammarBuilder Overload

Microsoft.Speech.Recognition Namespace

Choices

Grammar