Share via


Note

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

GrammarBuilder Constructor (String, Int32, Int32)

Initializes a new instance of the GrammarBuilder class from the sequence of words in a String and specifies how many times the String can be repeated.

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

Syntax

'Declaration
Public Sub New ( _
    phrase As String, _
    minRepeat As Integer, _
    maxRepeat As Integer _
)
'Usage
Dim phrase As String
Dim minRepeat As Integer
Dim maxRepeat As Integer

Dim instance As New GrammarBuilder(phrase, _
    minRepeat, maxRepeat)
public GrammarBuilder(
    string phrase,
    int minRepeat,
    int maxRepeat
)

Parameters

  • minRepeat
    Type: System.Int32
    The minimum number of times that input matching the phrase must occur to constitute a match.
  • maxRepeat
    Type: System.Int32
    The maximum number of times that input matching the phrase 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. For more information about building a speech recognition grammar that contains strings, see Use a String to Create a GrammarBuilder (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".

private static Grammar CreatePizzaGrammar()
{

  // Create a Choices object with alternatives for 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

Reference

GrammarBuilder Class

GrammarBuilder Members

GrammarBuilder Overload

Microsoft.Speech.Recognition Namespace

Choices

Grammar