GrammarBuilder Constructor (GrammarBuilder, Int32, Int32)

Microsoft Speech Platform SDK 11

Collapse image Expand Image Copy image CopyHover image

Initializes a new instance of the GrammarBuilder class for a repeated element.

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

Syntax

Visual Basic (Declaration)
Public Sub New ( _
	builder As GrammarBuilder, _
	minRepeat As Integer, _
	maxRepeat As Integer _
)
Visual Basic (Usage)
Dim builder As GrammarBuilder
Dim minRepeat As Integer
Dim maxRepeat As Integer

Dim instance As New GrammarBuilder(builder, _
	minRepeat, maxRepeat)
C#
public GrammarBuilder(
	GrammarBuilder builder,
	int minRepeat,
	int maxRepeat
)

Parameters

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

The repeated element.

minRepeat
Type: System..::..Int32

The minimum number of times that input matching the element defined by builder must occur to constitute a match.

maxRepeat
Type: System..::..Int32

The maximum number of times that input matching the element defined by builder can occur to constitute a match.

Remarks

If the value of minRepeat is 0, then the new GrammarBuilder represents an optional element.

The value of minRepeat must be greater than or equal to 0 and less than or equal to the value of maxRepeat.

Important noteImportant

When you specify repeats for GrammarBuilder objects that contain SemanticResultValue or SemanticResultKey instances, make sure you avoid creating duplicate semantic elements with the same key name or multiple semantic elements that could repeatedly modify the Value property of a SemanticValue object. The speech recognizer can throw an exception if it encounters these circumstances. For more information about building a speech recognition grammar that contains semantic information, see Add Semantics to a GrammarBuilder Grammar (Microsoft.Speech).

Examples

The following example creates a speech recognition grammar for ordering a pizza. It starts with an optional, opening phrase, followed by one to four toppings, and closes with the word "pizza".

C# Copy imageCopy Code
private static Grammar CreatePizzaGrammar()
{

  // Create a Choices object from a string array of alternative toppings.
  Choices toppings = new Choices(new string[] {
    "cheese", "mushroom", "tomato", "onion",
    "anchovy", "chicken", "pepperoni"});
  
  // Create a GrammarBuilder and append the Choices object.
  GrammarBuilder andToppings = new GrammarBuilder("and", 0, 1);
  andToppings.Append(toppings);

  // Construct the phrase.
  GrammarBuilder gb = new GrammarBuilder("I would like a", 0, 1);
  gb.Append(toppings);
  gb.Append(new GrammarBuilder(andToppings, 0, 3));
  gb.Append("pizza");

  // Create the Grammar from the GrammarBuilder.
  Grammar grammar = new Grammar(gb);
  grammar.Name = "Pizza Order";

  return grammar;
}

See Also