SrgsOneOf.Add Method

Adds a set of alternative phrases that can possibly be matched by a user.

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




  • item
    Any valid rule expansion. A valid rule expansion can consist of a word or other entity that can be spoken, an SrgsRuleRef element, an SrgsTag element, or any logical combination of these.


Exception type Condition

item is null.


Each alternative word or phrase is contained within an SrgsItem element.


The following example creates an inline grammar with an SrgsOneOf element and adds text words or phrases from a list of resources as SrgsItem elements to the SrgsOneOf element. These SrgsItem elements are 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.Root = rule1;

  ResourceInfo resources = TaskletHost.Resources;

  SrgsOneOf ListOfAlternatives = new SrgsOneOf();

  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.


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


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