Share via


Note

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

Grammar Constructor (GrammarBuilder)

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

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

Syntax

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

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

Parameters

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.

// 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

Reference

Grammar Class

Grammar Members

Grammar Overload

Microsoft.Speech.Recognition Namespace

GrammarBuilder

Grammar

Other Resources

Speech Recognition Grammar Specification Version 1.0