Grammar Constructor (GrammarBuilder)

Microsoft Speech Platform SDK 11

Collapse image Expand Image Copy image CopyHover image

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

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

Syntax

Visual Basic (Declaration)
Public Sub New ( _
	builder As GrammarBuilder _
)
Visual Basic (Usage)
Dim builder As GrammarBuilder

Dim instance As New Grammar(builder)
C#
public Grammar(
	GrammarBuilder builder
)

Parameters

builder
Type: Microsoft.Speech.Recognition..::..GrammarBuilder

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

Examples

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

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

C# Copy imageCopy Code
// 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;
}

See Also