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.5.2, 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft