This documentation is archived and is not being maintained.

SrgsText Class

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)

[SerializableAttribute]
public ref class SrgsText : public SrgsElement

The SrgsText type exposes the following members.

  NameDescription
Public methodSrgsText()Initializes a new instance of the SrgsText class.
Public methodSrgsText(String)Initializes a new instance of the SrgsText class, specifying the text of the instance.
Top

  NameDescription
Public propertyTextGets or sets the text contained within the SrgsText class instance.
Top

  NameDescription
Public methodCreateObjRefCreates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.)
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetLifetimeServiceRetrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodInitializeLifetimeServiceObtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Protected methodMemberwiseClone()Creates a shallow copy of the current Object. (Inherited from Object.)
Protected methodMemberwiseClone(Boolean)Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

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.Rules.Add(size);
document.Root = size;

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

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 -->
<one-of>
  <item>Small</item>
  <item>Medium</item>
  <item>Large</item>
</one-of>

.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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

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