Export (0) Print
Expand All

Grammar Constructor (SrgsDocument)

Initializes a new instance of a Grammar class from an SrgsDocument object.

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

public Grammar(
	SrgsDocument srgsDocument


Type: System.Speech.Recognition.SrgsGrammar.SrgsDocument

The constraints for the speech recognition grammar.


srgsDocument does not contain a root rule.


srgsDocument is null.


srgsDocument contains a rule reference that cannot be resolved.

This constructor does not pass any parameters to the initialization handler, and the SrgsDocument should not contain an initialization handler that requires arguments.

A SrgsDocument can have a root rule. To create a Grammar object that specifies a root rule, use the Grammar or Grammar constructor.

To create a speech recognition Grammar from an SrgsDocument and specify a base URI to use to resolve relative rule references, use the Grammar constructor.

The following example creates a speech recognition grammar in an SrgsDocument instance, which is then used to construct a Grammar object.

private static Grammar CreateSrgsDocumentGrammar()
  // Create the SrgsDocument.
  SrgsDocument document = new SrgsDocument();

  // Create the Cities rule and add it to the document.
  SrgsRule citiesRule = new SrgsRule("Cities");

  SrgsOneOf cityChoice = new SrgsOneOf();
  cityChoice.Add(new SrgsItem("Seattle"));
  cityChoice.Add(new SrgsItem("Los Angeles"));
  cityChoice.Add(new SrgsItem("New York"));
  cityChoice.Add(new SrgsItem("Miami"));


  // Create the Main rule and add it to the document.
  SrgsRule mainRule = new SrgsRule("Main");
  mainRule.Scope = SrgsRuleScope.Public;

  SrgsItem item = new SrgsItem("I would like to fly from");
  item.Add(new SrgsRuleRef(citiesRule));
  item.Add(new SrgsText("to"));
  item.Add(new SrgsRuleRef(citiesRule));


  // Set the root rule.
  document.Root = mainRule;

  // Create the Grammar object.
  Grammar citiesGrammar = new Grammar(document);
  citiesGrammar.Name = "SrgsDocument Cities Grammar";

  return citiesGrammar;

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

© 2014 Microsoft