Leggere in inglese Modifica

Condividi tramite


RecognizedWordUnit Class

Definition

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Provides the atomic unit of recognized speech.

C#
public class RecognizedWordUnit
C#
[System.Serializable]
public class RecognizedWordUnit
Inheritance
RecognizedWordUnit
Attributes

Examples

The following example shows a utility routine (stringFromWordArray) that generates strings. The strings contain lexical output (using LexicalForm), normalized text (using Text), or phonetic characters from the International Phonetic Alphabet (using Pronunciation). Strings are formatted using DisplayAttributes objects obtained from the DisplayAttributes property from a ReadOnlyCollection<T> of RecognizedWordUnit objects. The RecognizedWordUnit objects are obtained from the Words property on the RecognizedPhrase object.

C#
internal enum WordType
{
  Text,
  Normalized = Text,
  Lexical,
  Pronunciation
}
C#
internal static string stringFromWordArray(ReadOnlyCollection<RecognizedWordUnit> words, WordType type)
{
  string text = "";
  foreach (RecognizedWordUnit word in words)
  {
    string wordText = "";
    if (type == WordType.Text || type == WordType.Normalized)
    {
      wordText = word.Text;
    }
    else if (type == WordType.Lexical)
    {
      wordText = word.LexicalForm;
    }
    else if (type == WordType.Pronunciation)
    {
      wordText = word.Pronunciation;
    }
    else
    {
      throw new InvalidEnumArgumentException(String.Format("[0}: is not a valid input", type));
    }
    // Use display attribute

    if ((word.DisplayAttributes & DisplayAttributes.OneTrailingSpace) != 0)
    {
      wordText += " ";
    }
    if ((word.DisplayAttributes & DisplayAttributes.TwoTrailingSpaces) != 0)
    {
      wordText += "  ";
    }
    if ((word.DisplayAttributes & DisplayAttributes.ConsumeLeadingSpaces) != 0)
    {
      wordText = wordText.TrimStart();
    }
    if ((word.DisplayAttributes & DisplayAttributes.ZeroTrailingSpaces) != 0)
    {
      wordText = wordText.TrimEnd();
    }

    text += wordText;

  }
  return text;
}

Remarks

All results returned by a recognition engine are constructed of RecognizedWordUnit objects.

An array of RecognizedWordUnit objects is accessible for any recognition operation through the Words property on the RecognizedPhrase object.

In addition to providing a measure of recognition certainty (Confidence) a RecognizedWordUnit instance provides:

  • Normalized and exact (or lexical) text representations for a recognized word. For more information, see ReplacementText, Text, and LexicalForm.

  • Pronunciation information using characters from a supported phonetic alphabet, such as the International Phonetic Alphabet (IPA) or the Universal Phone Set (UPS). For more information see Pronunciation.

  • Formatting for printing. For more information see the DisplayAttributes class and its DisplayAttributes property.

Constructors

Properties

Confidence

Gets a value, assigned by the recognizer, that represents the likelihood that a recognized word matches a given input.

DisplayAttributes

Gets formatting information used to create the text output from the current RecognizedWordUnit instance.

LexicalForm

Gets the unnormalized text of a recognized word.

Pronunciation

Gets the phonetic spelling of a recognized word.

Text

Gets the normalized text for a recognized word.

Methods

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to

Prodotto Versioni
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)

See also