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


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");

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

  return citiesGrammar;

.NET Framework
Available since 3.0
Return to top