Export (0) Print
Expand All

RecognizedWordUnit Constructor

Initializes a new instance of the RecognizedWordUnit class.

Namespace:  System.Speech.Recognition
Assembly:  System.Speech (in System.Speech.dll)

public RecognizedWordUnit(
	string text,
	float confidence,
	string pronunciation,
	string lexicalForm,
	DisplayAttributes displayAttributes,
	TimeSpan audioPosition,
	TimeSpan audioDuration
)

Parameters

text
Type: System.String

The normalized text for a recognized word.

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

confidence
Type: System.Single

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

pronunciation
Type: System.String

The phonetic spelling of a recognized word.

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

lexicalForm
Type: System.String

The unnormalized text for a recognized word.

This argument is required and may not be null, "", or Empty.

displayAttributes
Type: System.Speech.Recognition.DisplayAttributes

Defines the use of white space to display recognized words.

audioPosition
Type: System.TimeSpan

The location of the recognized word in the audio input stream.

This value can be Zero.

audioDuration
Type: System.TimeSpan

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

This value can be Zero.

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.

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

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft