GrammarBuilder.Append Method (String, Int32, Int32)

Appends a grammar rule string to the current GrammarBuilder with minimum and maximum repetition counters.

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

Syntax

'Declaration
Public Sub Append ( _
    phrase As String, _
    minRepeat As Integer, _
    maxRepeat As Integer _
)
public void Append (
    string phrase,
    int minRepeat,
    int maxRepeat
)
public:
void Append (
    String^ phrase, 
    int minRepeat, 
    int maxRepeat
)
public void Append (
    String phrase, 
    int minRepeat, 
    int maxRepeat
)
public function Append (
    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 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 appended with minimum and maximum repeats defined:

  • The code groceryGB.Append("please",0,1); appends grammar logic to the current GrammarBuilder (groceryGB) to match audio inputs with either one or no occurrence of the word “please”.

  • The code GrammarBuilder productsGB = new GrammarBuilder((GrammarBuilder)productsChoices,1,5); appends grammar logic to the current GrammarBuilder (groceryGB) to match audio inputs with one to five occurrences which will satisfy a Choices (productsChoices)

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

Thread Safety

All public static (Shared in Visual Basic) members of this type are thread-safe. Instance members are not guaranteed to be thread-safe.

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