Κοινή χρήση μέσω


RecognizedWordUnit Constructor

Definition

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)

Parameters

text
String

The normalized text for a recognized word.

This value can be null, "", or Empty.

confidence
Single

A float value from 0.0 through 1.0 indicating the certainty of word recognition.

pronunciation
String

The phonetic spelling of a recognized word.

This value can be null, "", or Empty.

lexicalForm
String

The unnormalized text for a recognized word.

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.

This value can be Zero.

audioDuration
TimeSpan

The length of the audio input corresponding to the recognized word.

This value can be Zero.

Examples

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;
      }
    }
  }
}

Remarks

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.

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.

For actual applications, do not directly construct RecognizedWordUnit, rather obtain it through the Words property on the RecognizedPhrase object.

Applies to

See also