Text Property

Microsoft Speech Platform SDK 11

Collapse imageExpand ImageCopy imageCopyHover image

Gets the normalized text generated by a speech recognition engine from recognized input.

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

Syntax

Visual Basic (Declaration)
Public ReadOnly Property Text As String
	Get
Visual Basic (Usage)
Dim instance As RecognizedPhrase
Dim value As String

value = instance.Text
C#
public string Text { get; }

Property Value

Type: System..::..String

The normalized text generated by a speech recognition engine from recognized input.

Remarks

As part of the speech recognition process, the speech recognition engine performs speech-to-text normalization of the recognized input into a display form.

For example, the spoken input, "twenty five dollars", generates a recognition result where the Words property contains the words, "twenty", "five", and "dollars", and the Text property contains the phrase, "$25.00". For more information about text normalization, see ReplacementText.

Examples

The example below is a handler for displaying to a user interface the result of recognition events. The handler uses Text on an instance of RecognizedPhraseto display the recognized text from the recognition candidate in the Alternates collection with the highest Confidence score.

C# Copy imageCopy Code
private void DisplayResult(EventArgs eventArgs) 
{
  // Make sure all different event types are supported.
  RecognitionResult result = null;
  if (null != (eventArgs as RecognitionEventArgs)) 
  {
    result = (eventArgs as RecognitionEventArgs).Result;
  } 
  else if (null != (eventArgs as EmulateRecognizeCompletedEventArgs)) 
  {
    result = (eventArgs as EmulateRecognizeCompletedEventArgs).Result;
  }

  // In all cases, clear results, semantic XML, semantics tree, and alternates.
  _recognitionSmlBrowser.Navigate("about:blank");
  _semanticsTreeView.Nodes.Clear();
  //            _candidateList.Items.Clear();
  _candidateList.DataSource = null;
  _candidateList.DisplayMember = null;
  _phraseInfoLabel.Text = "";
  _bestCandidateTextBox.Text = "";

  if (result != null) 
  {
    // Obtain result from RecognitionEventArg passed in.
    // Set Text color on the basis of the event type passed in.
    switch (eventArgs.GetType().ToString()) 
    {
      case "Microsoft.Speech.Recognition.SpeechHypothesizedEventArgs":
        _bestCandidateTextBox.ForeColor = Color.Black;
        _bestCandidateTextBox.Text = result.Text;
        _phraseInfoLabel.Text = null;
        break;
      case "Microsoft.Speech.Recognition.SpeechRecognitionRejectedEventArgs":
        _bestCandidateTextBox.ForeColor = Color.OrangeRed;
        _bestCandidateTextBox.Text = "Unable to Recognize Input";
        _phraseInfoLabel.Text = String.Format("Rejected Phrase Information\n");
        Utils.DisplayBasicPhraseInfo(_phraseInfoLabel, result, _recognizer);
        Utils.DisplaySemanticsSML(_recognitionSmlBrowser, result);
        Utils.DisplaySemanticsTreeView(_semanticsTreeView, result.Semantics);
        break;
      case "Microsoft.Speech.Recognition.SpeechRecognizedEventArgs":
        _bestCandidateTextBox.ForeColor = Color.Green;
        _bestCandidateTextBox.Text = result.Text;
        _phraseInfoLabel.Text = String.Format("Recognized Phrase Information\n");

        Utils.DisplayBasicPhraseInfo(_phraseInfoLabel, result, _recognizer);
        Utils.DisplaySemanticsSML(_recognitionSmlBrowser, result);
        Utils.DisplaySemanticsTreeView(_semanticsTreeView, result.Semantics);
        break;
      case "Microsoft.Speech.Recognition.EmulateRecognizeCompletedEventArgs":
        _bestCandidateTextBox.ForeColor = Color.Green;
        _bestCandidateTextBox.Text = result.Text;
        _phraseInfoLabel.Text = String.Format("Recognized Phrase Information\n");
        Utils.DisplayBasicPhraseInfo(_phraseInfoLabel, result, _recognizer);
        Utils.DisplaySemanticsSML(_recognitionSmlBrowser, result);
        Utils.DisplaySemanticsTreeView(_semanticsTreeView, result.Semantics);
        break;
      default:
        _bestCandidateTextBox.ForeColor = Color.Black;
        break;
    }

    Utils.DisplayDataOnListBox(_candidateList, result.Alternates, "Text");

  }
}

See Also