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分、シアトルワシントンのパイクプレイス市場で114ドルと6セントで1ポイント6kgの魚を買った。

これは、正規化後の同じテキストです。

"7 月 4 日午後 12:31, 私はのために魚の 1.6 kg を買った $14.06, シアトルのパイクプレース市場で WA 98122"

この例では 5 つの置換があり、それぞれが の ReplacementTextインスタンスによって記述されます。

オブジェクトを ReplacementText 使用すると、アプリケーションで次の情報を確認できます。

  • 正規化で置き換えられた単語の位置と数。 詳細については、CountOfWordsFirstWordIndex」または」を参照してください。

  • 置換されたテキストとその表示属性。 詳細については、「Text」および「DisplayAttributes」を参照してください。

ReplacementTextのインスタンスは、通常、 の プロパティRecognizedPhraseによってReplacementWordUnits返される オブジェクトのCollection<T>メンバーとして取得されます (または、 から継承RecognizedPhraseされるクラスなどRecognitionResult) は、返されたテキストが正規化されている場合です。

プロパティ

CountOfWords

音声正規化手順で置換された、認識された単語の数を取得します。

DisplayAttributes

音声正規化手順に置換されたテキストの先頭と末尾の空白に関する情報を取得します。

FirstWordIndex

音声正規化手順で置換された、最初に認識された単語の場所を取得します。

Text

音声正規化手順で置換された、認識されたテキストを取得します。

メソッド

Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)

適用対象