Export (0) Print
Expand All

Grammar Constructor (GrammarBuilder)

Initializes a new instance of the Grammar class from a GrammarBuilder object.

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

public Grammar(
	GrammarBuilder builder
)

Parameters

builder
Type: System.Speech.Recognition.GrammarBuilder

An instance of GrammarBuilder that contains the constraints for the speech recognition grammar.

For more information about using the GrammarBuilder class to define a grammar, see Create Grammars Using GrammarBuilder.

The following example creates a speech recognition grammar using Choices and GrammarBuilder objects. The Grammar constructor creates a Grammar object from the GrammarBuilder object.

// Create a grammar using a GrammarBuilder and return the new grammar. 
private static Grammar CreateGrammarBuilderGrammar()
{
  GrammarBuilder builder = new GrammarBuilder();

  Choices cityChoice = new Choices (new string[] 
  {"Seattle", "New York", "Miami", "Los Angeles"});

  builder.Append("I would like to fly from");
  builder.Append(cityChoice);
  builder.Append("to");
  builder.Append(cityChoice);

  Grammar citiesGrammar = new Grammar(builder);
  citiesGrammar.Name = "GrammarBuilder Cities Grammar";

  return citiesGrammar;
}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4
Show:
© 2015 Microsoft