ReplacementText 類別

定義

包含在辨識結果上執行的語音正規化程序的相關資訊。

public ref class ReplacementText
[System.Serializable]
public class ReplacementText
[<System.Serializable>]
type ReplacementText = class
Public Class ReplacementText
繼承
ReplacementText
屬性

範例

下列範例會在使用者介面中顯示辨識 RecognizedPhrase 引擎所傳回之物件的相關資訊。

internal static void DisplayBasicPhraseInfo(  
        Label label,   
        RecognizedPhrase result,   
        SpeechRecognizer rec)   
{  
  if (result != null && label != null)   
  {  
    // Blank  
    if (rec != null)   
    {   
      // Clear  
      label.Text += String.Format(  
                             "  Recognizer currently at:   {0} mSec\n" +  
                             "  Audio Device currently at: {1} mSec\n",  
                             rec.RecognizerAudioPosition.TotalMilliseconds,  
                             rec.AudioPosition.TotalMilliseconds);  
    }  

    if (result != null)   
    { // Clear  
      RecognitionResult recResult = result as RecognitionResult;  
      if (recResult != null)   
      {  
        RecognizedAudio resultAudio = recResult.Audio;  
        if (resultAudio == null)   
        {  
          label.Text += String.Format("  Emulated input\n");  
        }   
        else   
        {  
          label.Text += String.Format(  
                               "  Candidate Phrase at:       {0} mSec\n" +  
                               "  Phrase Length:             {1} mSec\n" +  
                               "  Input State Time:          {2}\n" +  
                               "  Input Format:              {3}\n",  
                               resultAudio.AudioPosition.TotalMilliseconds,  
                               resultAudio.Duration.TotalMilliseconds,  
                               resultAudio.StartTime.ToShortTimeString(),  
                               resultAudio.Format.EncodingFormat.ToString());  
        }  
      }  

      label.Text += String.Format("  Confidence Level:          {0}\n", result.Confidence);  
      if (result.Grammar != null)   
      {  
        label.Text += String.Format(  
                            "  Recognizing Grammar:       {0}\n" +  
                            "  Recognizing Rule:          {1}\n",  
                            ((result.Grammar.Name != null) ? (result.Grammar.Name) : "None"),  
                            ((result.Grammar.RuleName != null) ? (result.Grammar.RuleName) : "None"));  
      }  

      if  (result.ReplacementWordUnits.Count !=  0)    
      {  
        label.Text += String.Format("  Replacement text:\n");  
        foreach (ReplacementText rep in result.ReplacementWordUnits)    
        {  
          string repText = rep.Text;  
          // Add trailing spaces  

          if ((rep.DisplayAttributes & DisplayAttributes.OneTrailingSpace) !=  0)    
          {  
            repText += " ";  
          }  
          if ((rep.DisplayAttributes & DisplayAttributes.TwoTrailingSpaces) !=  0)    
          {  
            repText += "  ";  
          }  
          if ((rep.DisplayAttributes & DisplayAttributes.ConsumeLeadingSpaces) != 0)    
          {  
            repText=repText.TrimStart();  
          }  
          if ((rep.DisplayAttributes & DisplayAttributes.ZeroTrailingSpaces) != 0)   
          {  
            repText = repText.TrimEnd();  
          }  
          label.Text += String.Format(  
                           "      At index {0} for {1} words. Text: \"{2}\"\n",  
                           rep.FirstWordIndex,  rep.CountOfWords, repText);  

        }  
        label.Text += String.Format("\n\n");  
      }  
    }  
  }    
}  

備註

語音正規化是使用特殊的結構或符號來表達書寫的語音。

例如,假設這是可辨識的文字:

「7月4日下午 12 31,在西雅圖華盛頓 9 8 1 2 2 特區的 pike 市市集中,有14美元和6美分的點6千克

這是正規化之後的相同文字:

「下午12:31 年7月4日,我購買1.6 公斤 $14.06 的公斤,pike 地點市場在西雅圖 WA 98122」

在此範例中,有五個替代項,其中每一個都是由的實例所描述 ReplacementText

使用 ReplacementText 物件時,應用程式可以判斷:

的實例 ReplacementText 通常會以 Collection<T> ReplacementWordUnits (上的屬性 RecognizedPhrase 或繼承自之類別的成員形式取得 RecognizedPhrase ,例如 RecognitionResult 在傳回的文字正規化時) 。

屬性

CountOfWords

取得由語音正規化程序取代的辨識字數目。

DisplayAttributes

取得語音正規化程序所取代之文字的前置及尾端空格的相關資訊。

FirstWordIndex

取得由語音正規化程序取代的第一個辨識字的位置。

Text

取得由語音正規化程序取代的辨識文字。

方法

Equals(Object)

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

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

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

(繼承來源 Object)

適用於