Share via


GrammarBuilder Constructor (String, Int32, Int32)

Constructs a GrammarBuilder that can generate a Grammar requiring that audio input is to be checked for matching against repeated occurrences of a given phrase.

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 _
)
public GrammarBuilder (
    string phrase,
    int minRepeat,
    int maxRepeat
)
public:
GrammarBuilder (
    String^ phrase, 
    int minRepeat, 
    int maxRepeat
)
public GrammarBuilder (
    String phrase, 
    int minRepeat, 
    int maxRepeat
)
public function GrammarBuilder (
    phrase : String, 
    minRepeat : int, 
    maxRepeat : int
)

Parameters

  • phrase
    A System.String instance containing a phrase to match against audio input.
  • minRepeat
    Specifies the minimum number of times the audio input matching the System.String specified by the phrase parameter can be repeated and still be successfully recognized.
  • maxRepeat
    Specifies the maximum number of times the audio input matching the System.String specified by the phrase parameter can be repeated and still be successfully recognized.

Remarks

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

Example

In the example below a Grammar is built that will to support recognizing an audio input which may optionally begin with “please”, must have the input “give me”, and five inputs matching a Choices option.

For example the inputs “give me pear soap” and “please give me apple soap pear” will be matched.

To implement the Grammar, two GrammarBuilder instances are constructed with minimum and maximum repeats defined:

  • The GrammarBuilder instance productsGB is constructed to match audio inputs with one to five occurrences which will satisfy a Choices (productsChoices), and is constructed with GrammarBuilder(String,Int32,Int32).

  • The GrammarBuilder instance politeness is constructed to match audio inputs with either one or no occurrence of the word “please”, and is constructed with GrammarBuilder(GrammarBuilder,Int32,Int32).

private void groceryGrammar() {
    GrammarBuilder politeness = new GrammarBuilder("please", 0, 1);
    GrammarBuilder order = new GrammarBuilder("give me");
    Choices productsChoices = new Choices("apple", "pear", "banana", "apples", "pears", "bananas", "soap", "milk");
    GrammarBuilder productsGB = new GrammarBuilder((GrammarBuilder)productsChoices, 1, 5);
    GrammarBuilder groceryGB = politeness + order + new SemanticResultKey("Products", productsGB);
    Grammar grammar = new Grammar(groceryGB);
    grammar.Enabled = true;
    grammar.Name = "Grocery Grammar";
    _recognizer.LoadGrammar(grammar);
}private void groceryGrammar() {
    GrammarBuilder politeness = new GrammarBuilder("please", 0, 1);
    GrammarBuilder order = new GrammarBuilder("give me");
    Choices productsChoices = new Choices("apple", "pear", "banana", "apples", "pears", "bananas", "soap", "milk");
    GrammarBuilder productsGB = new GrammarBuilder((GrammarBuilder)productsChoices, 1, 5);
    GrammarBuilder groceryGB = politeness + order + new SemanticResultKey("Products", productsGB);
    Grammar grammar = new Grammar(groceryGB);
    grammar.Enabled = true;
    grammar.Name = "Grocery Grammar";
    _recognizer.LoadGrammar(grammar);
}

Platforms

Development Platforms

Windows XP Professional with Service Pack 2 (SP2), Windows Server 2003, Windows Vista Ultimate Edition, Windows Vista Business Edition, Windows Vista Enterprise Edition

Target Platforms

See Also

Reference

GrammarBuilder Class
GrammarBuilder Members
Microsoft.Speech.Recognition Namespace