SrgsText Class


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Represents the textual content of grammar elements defined by the World Wide Web Consortium (W3C) Speech Recognition Grammar Specification (SRGS) Version 1.0.

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


public class SrgsText : SrgsElement


Initializes a new instance of the SrgsText class.


Initializes a new instance of the SrgsText class, specifying the text of the instance.


Gets or sets the text contained within the SrgsText class instance.


Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.(Inherited from MarshalByRefObject.)


Determines whether the specified object is equal to the current object.(Inherited from Object.)


Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)


Serves as the default hash function. (Inherited from Object.)


Retrieves the current lifetime service object that controls the lifetime policy for this instance.(Inherited from MarshalByRefObject.)


Gets the Type of the current instance.(Inherited from Object.)


Obtains a lifetime service object to control the lifetime policy for this instance.(Inherited from MarshalByRefObject.)


Creates a shallow copy of the current Object.(Inherited from Object.)


Creates a shallow copy of the current MarshalByRefObject object.(Inherited from MarshalByRefObject.)


Returns a string that represents the current object.(Inherited from Object.)

The SrgsText class represents the text found within a set of SRGS element tags. When an SrgsItem object is constructed with a String parameter, a SrgsText object is created with its Text property initialized to the value of that parameter. The Text object is then added to the Elements collection on the SrgsItem object.

The following C# code example demonstrates how to use the SrgsText class to modify the textual contents of SrgsItem objects. The example changes the initial text values of the SrgsItem objects (Large, Larger, and Largest) to Small, Medium, and Large, respectively.

// Create SrgsItem objects and specify their text.
SrgsItem smallItem = new SrgsItem("Large");
SrgsItem mediumItem = new SrgsItem("Larger");
SrgsItem largeItem = new SrgsItem("Largest");

SrgsText textOfItem = null;

//  Change the text of smallItem.
if (smallItem.Elements[0] is SrgsText)
  textOfItem = smallItem.Elements[0] as SrgsText;
  textOfItem.Text = "Small";

//  Change the text of mediumItem.
if (mediumItem.Elements[0] is SrgsText)
  textOfItem = mediumItem.Elements[0] as SrgsText;
  textOfItem.Text = "Medium";

// Change the text of largeItem.
if (largeItem.Elements[0] is SrgsText)
  textOfItem = largeItem.Elements[0] as SrgsText;
  textOfItem.Text = "Large";

// Create an SrgsOneOf object and add smallItem, mediumItem, 
// and largeItem as alternatives.
SrgsOneOf itemSize = new SrgsOneOf(new SrgsItem[] 
  { smallItem, mediumItem, largeItem });

// Create a new SrgsRule from the SrgsOneOf object, and specifiy its identifier.
SrgsRule size = new SrgsRule("Sizes", itemSize);

// Create an SrgsDocument object.
// Add the SrgsRule object to the collection of rules and make it the root rule.
SrgsDocument document = new SrgsDocument(); 
document.Root = size;

// Write the SrgsDocument to an XML grammar file.
string srgsDocumentFile = Path.Combine(Path.GetTempPath(), "srgsDocumentFile.xml");
XmlWriter writer = XmlWriter.Create(srgsDocumentFile);

The following shows how the modified text of the SrgsItem objects would appear as item elements in the output XML grammar file.

<!-- SRGS XML Fragment -->

.NET Framework
Available since 3.0

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

Return to top