RecognizedWordUnit Constructor

Microsoft Speech Platform SDK 11

Collapse imageExpand ImageCopy imageCopyHover image

Initializes a new instance of the RecognizedWordUnit class.

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

Syntax

Visual Basic (Declaration)
Public Sub New ( _
	text As String, _
	confidence As Single, _
	pronunciation As String, _
	lexicalForm As String, _
	displayAttributes As DisplayAttributes, _
	audioPosition As TimeSpan, _
	audioDuration As TimeSpan _
)
Visual Basic (Usage)
Dim text As String
Dim confidence As Single
Dim pronunciation As String
Dim lexicalForm As String
Dim displayAttributes As DisplayAttributes
Dim audioPosition As TimeSpan
Dim audioDuration As TimeSpan

Dim instance As New RecognizedWordUnit(text, confidence, _
	pronunciation, lexicalForm, displayAttributes, _
	audioPosition, audioDuration)
C#
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 may be nullNothingnullptrunita null reference (Nothing in Visual Basic), "", 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 may be nullNothingnullptrunita null reference (Nothing in Visual Basic), "", or Empty.

lexicalForm
Type: System..::..String

The unnormalized text for a recognized word.

This argument is required and may not be nullNothingnullptrunita null reference (Nothing in Visual Basic), "", or Empty.

displayAttributes
Type: Microsoft.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 may be Zero

audioDuration
Type: System..::..TimeSpan

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

This value may be Zero

Remarks

If text or pronunciation are nullNothingnullptrunita null reference (Nothing in Visual Basic), "", 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 with when emulating recognition operations using EmulateRecognizeAsync or EmulateRecognize.

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

Examples

The example below is a somewhat contrived test of emulation, where new words are generated from the input and passed to the emulator, and then verified.

C# Copy imageCopy Code
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++) {
    //DisplayAttributes at=
    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;
        }
    }
}

See Also