SrgsText 類別

定義

表示由全球資訊網協會 (W3C) 語音辨識文法規格 (SRGS) 1.0 版 \(英文\) 所定義之文法元素的文字內容。

public ref class SrgsText : System::Speech::Recognition::SrgsGrammar::SrgsElement
[System.Serializable]
public class SrgsText : System.Speech.Recognition.SrgsGrammar.SrgsElement
[<System.Serializable>]
type SrgsText = class
    inherit SrgsElement
Public Class SrgsText
Inherits SrgsElement
繼承
屬性

範例

下列 C# 程式碼範例示範如何使用 SrgsText 類別來修改 物件的文字內容 SrgsItem 。 此範例會將 物件的初始文字值 SrgsItem 分別 (、 LargerLargest) 變更為 SmallMediumLargeLarge

// 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 specify 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();  

以下顯示物件的修改文字 SrgsItem 如何顯示為 item 輸出 XML 文法檔案中的元素。

<!-- SRGS XML Fragment -->  
<one-of>  
  <item>Small</item>  
  <item>Medium</item>  
  <item>Large</item>  
</one-of>  

備註

類別 SrgsText 代表在一組 SRGS 專案標記內找到的文字。 SrgsItem使用 參數建構 String 物件時, SrgsText 會建立 物件,並將其 Text 屬性初始化為該參數的值。 然後,物件 Text 會新增至 Elements 物件上的 SrgsItem 集合。

建構函式

SrgsText()

初始化 SrgsText 類別的新執行個體。

SrgsText(String)

初始化 SrgsText 類別的新執行個體,並執行個體的文字。

屬性

Text

取得或設定包含在 SrgsText 類別執行個體中的文字。

方法

CreateObjRef(Type)

建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。

(繼承來源 MarshalByRefObject)
Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetLifetimeService()
已淘汰.

擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。

(繼承來源 MarshalByRefObject)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
InitializeLifetimeService()
已淘汰.

取得存留期服務物件,以控制這個執行個體的存留期原則。

(繼承來源 MarshalByRefObject)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
MemberwiseClone(Boolean)

建立目前 MarshalByRefObject 物件的淺層複本。

(繼承來源 MarshalByRefObject)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於

另請參閱