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 類別的 SpeechRecognitionEngine 或 EmulateRecognizeAsyncEmulateRecognizeAsync 方法 SpeechRecognizer 模擬辨識作業時,才會直接 EmulateRecognize 建構 RecognizedWordUnit 實例。
對於實際應用程式,請勿直接建構 RecognizedWordUnit ,而是透過 Words 物件上的 RecognizedPhrase 屬性取得它。