RecognizedWordUnit(String, Single, String, String, DisplayAttributes, TimeSpan, TimeSpan) 构造函数
定义
初始化 RecognizedWordUnit 类的新实例。Initializes a new instance of the RecognizedWordUnit class.
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
一个无法识别的字符串的正常化的文本。The normalized text for a recognized word.
- confidence
- Single
0.0 到 1.0 中指示单词标识的确定性的 float 值。A float value from 0.0 through 1.0 indicating the certainty of word recognition.
- pronunciation
- String
一个无法识别的单词的语音拼写。The phonetic spelling of a recognized word.
- lexicalForm
- String
一个识别字的非正常化文本。The unnormalized text for a recognized word.
需要使用此参数可能不是 null, " "或 Empty。This argument is required and may not be null, "", or Empty.
- displayAttributes
- DisplayAttributes
定义使用空白显示识别的词。Defines the use of white space to display recognized words.
- audioPosition
- TimeSpan
音频输入流的已识别的单词的位置。The location of the recognized word in the audio input stream.
- audioDuration
- TimeSpan
音频输入的长度对应已识别的单词。The length of the audio input corresponding to the recognized word.
示例
下面的示例是一个精心设计的模拟测试,其中,从输入生成新的词,然后将其传递给模拟器,然后进行验证。The following example is a somewhat contrived test of emulation, where new words are generated from the input and passed to the emulator, and then verified.
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 。If text or pronunciation are null, "", or Empty and the RecognizedWordUnit is used in a recognition operation, the recognition engine will generate appropriate values in any output RecognizedWordUnit instance.
直接构造 RecognizedWordUnit 实例通常仅在使用 EmulateRecognize 类的或 EmulateRecognizeAsync 方法 SpeechRecognitionEngine 和类的 EmulateRecognize 或 EmulateRecognizeAsync 方法 SpeechRecognizer 模拟识别操作时使用。Direct construction of RecognizedWordUnit instances is typically used only when emulating recognition operations using the EmulateRecognize or EmulateRecognizeAsync methods of the SpeechRecognitionEngine class and the EmulateRecognize or EmulateRecognizeAsync methods of the SpeechRecognizer class.
对于实际应用程序,不要直接构造 RecognizedWordUnit ,而是通过对象的 Words 属性获取它 RecognizedPhrase 。For actual applications, do not directly construct RecognizedWordUnit, rather obtain it through the Words property on the RecognizedPhrase object.