RecognizedWordUnit 构造函数
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
初始化 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)
参数
- confidence
- Single
0.0 到 1.0 中指示单词标识的确定性的 float
值。
- displayAttributes
- DisplayAttributes
定义使用空白显示识别的词。
示例
以下示例是模拟的一个有点特制的测试,其中从输入生成新单词并传递到仿真器,然后进行验证。
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;
}
}
}
}
注解
如果 text
或 pronunciation
为 null
、“”或 Empty ,并且 RecognizedWordUnit 用于识别操作,则识别引擎将在任何输出 RecognizedWordUnit 实例中生成适当的值。
仅当使用 EmulateRecognize 类的 或 EmulateRecognizeAsync 方法和 SpeechRecognitionEngine 类的 RecognizedWordUnit 或 EmulateRecognizeAsync 方法模拟识别操作时,EmulateRecognize才使用实例的SpeechRecognizer直接构造。
对于实际应用程序,不要直接构造 RecognizedWordUnit,而是通过 Words 对象上的 RecognizedPhrase 属性获取它。