RecognizedWordUnit 构造函数

定义

初始化 RecognizedWordUnit 类的新实例。

public:
 RecognizedWordUnit(System::String ^ text, float confidence, System::String ^ pronunciation, System::String ^ lexicalForm, System::Speech::Recognition::DisplayAttributes displayAttributes, TimeSpan audioPosition, TimeSpan audioDuration);
public RecognizedWordUnit (string text, float confidence, string pronunciation, string lexicalForm, System.Speech.Recognition.DisplayAttributes displayAttributes, TimeSpan audioPosition, TimeSpan audioDuration);
new System.Speech.Recognition.RecognizedWordUnit : string * single * string * string * System.Speech.Recognition.DisplayAttributes * TimeSpan * TimeSpan -> System.Speech.Recognition.RecognizedWordUnit
Public Sub New (text As String, confidence As Single, pronunciation As String, lexicalForm As String, displayAttributes As DisplayAttributes, audioPosition As TimeSpan, audioDuration As TimeSpan)

参数

text
String

一个无法识别的字符串的正常化的文本。

该值可以是 null、"" 或 Empty

confidence
Single

0.0 到 1.0 中指示单词标识的确定性的 float 值。

pronunciation
String

一个无法识别的单词的语音拼写。

该值可以是 null、"" 或 Empty

lexicalForm
String

一个识别字的非正常化文本。

需要使用此参数可能不是 null, " "或 Empty

displayAttributes
DisplayAttributes

定义使用空白显示识别的词。

audioPosition
TimeSpan

音频输入流的已识别的单词的位置。

此值可为 Zero

audioDuration
TimeSpan

音频输入的长度对应已识别的单词。

此值可为 Zero

示例

以下示例是模拟的一个有点特制的测试,其中从输入生成新单词并传递到仿真器,然后进行验证。

private void _emulateAndVerify_Click(object sender, EventArgs e)   
{  
  char[] delimiterChars = { ' ', ',', '.', ':', ';', '\t' };  
  string text = _emulateTextBox.Text;  
  string[] words = text.Split(delimiterChars);  

  RecognizedWordUnit[] InputWordUnits = new RecognizedWordUnit[words.Length];  
  for (int i = 0; i < words.Length; i++)   
  {  
    InputWordUnits[i] = new RecognizedWordUnit(  
        "",   
        0,   
        "",  
        words[i].ToLower(),   
        DisplayAttributes.OneTrailingSpace,   
        new TimeSpan(),   
        new TimeSpan());  
  }  

  RecognitionResult rec = _recognizer.EmulateRecognize(  
        InputWordUnits,   
        System.Globalization.CompareOptions.IgnoreCase);  
  if (rec == null)   
  {  
    MessageBox.Show(String.Format("Recognition emulation for {0} failed.\n", text));  
  }   
  else if (InputWordUnits.Length != rec.Words.Count)   
  {  
    MessageBox.Show(  
       String.Format("Length mismatch: Input was {0} words, Recognition has {1} words.\n}"));  
  }   
  else   
  {  
    for (int i = 0; i < InputWordUnits.Length; i++)   
    {  

      if (rec.Words[i].LexicalForm.ToLower() != InputWordUnits[i].LexicalForm.ToLower())   
      {  
        MessageBox.Show(  
          String.Format("Input word {0} \"{1}\" not found. Recognition output is {2}",  
          i, InputWordUnits[i].LexicalForm, rec.Words[i].LexicalForm));  
        continue;  
      }  
    }  
  }  
}  

注解

如果 textpronunciationnull、“”或 Empty ,并且 RecognizedWordUnit 用于识别操作,则识别引擎将在任何输出 RecognizedWordUnit 实例中生成适当的值。

仅当使用 EmulateRecognize 类的 或 EmulateRecognizeAsync 方法和 SpeechRecognitionEngine 类的 RecognizedWordUnitEmulateRecognizeAsync 方法模拟识别操作时,EmulateRecognize才使用实例的SpeechRecognizer直接构造。

对于实际应用程序,不要直接构造 RecognizedWordUnit,而是通过 Words 对象上的 RecognizedPhrase 属性获取它。

适用于

另请参阅