Note
Please see Azure Cognitive Services for Speech documentation for the latest supported speech solutions.
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.
Inheritance Hierarchy
System.Object
System.MarshalByRefObject
Microsoft.Speech.Recognition.SrgsGrammar.SrgsElement
Microsoft.Speech.Recognition.SrgsGrammar.SrgsText
Namespace: Microsoft.Speech.Recognition.SrgsGrammar
Assembly: Microsoft.Speech (in Microsoft.Speech.dll)
Syntax
'Declaration
<SerializableAttribute> _
Public NotInheritable Class SrgsText _
Inherits SrgsElement
'Usage
Dim instance As SrgsText
[SerializableAttribute]
public sealed class SrgsText : SrgsElement
Remarks
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.
Examples
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>
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.