SrgsRule.Add Method

Adds an SRGS element to a rule.

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

Syntax

'Declaration

Parameters

  • element
    Text or other XML elements that specify what speakers can say, and the order in which they can say it. A valid rule element must contain at least one piece of recognizable text or one rule reference.

Exceptions

Exception type Condition
ArgumentNullException

element is null.

Example

The following example creates an inline grammar with a single SrgsRule element and adds an SrgsOneOf element to the Elements property of the SrgsRule element. The SrgsOneOf element consists of SrgsItem elements containing alternatives to be recognized by the rule.

/// <summary>
/// Create an inline grammar
/// </summary>
/// <param name="mode">recognition mode: dtmf or voice</param>
protected void CreateInlineGrammar(SrgsGrammarMode mode)
{
  SrgsDocument grammar1 = new SrgsDocument();
  grammar1.Culture = Thread.CurrentThread.CurrentUICulture;
  grammar1.Mode = mode;

  //rule name is language independent 
  SrgsRule rule1 = new SrgsRule("rootRule");
  grammar1.Rules.Add(rule1);
  grammar1.Root = rule1;

  ResourceInfo resources = TaskletHost.Resources;

  SrgsOneOf ListOfAlternatives = new SrgsOneOf();
  rule1.Elements.Add(ListOfAlternatives);

  if (resources.GrammarTexts != null)
  {
    foreach (string alternative in resources.GrammarTexts)
    {
      ListOfAlternatives.Add(new SrgsItem(alternative));
    }
  }
  inlineGrammar = new Grammar(grammar1);

}

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

SrgsRule Class
SrgsRule Members
Microsoft.Speech.Recognition.SrgsGrammar Namespace