Share via


SpeechRecognitionEngine.SpeechHypothesized Event

Event raised when when the recognition engine detects speech and part of the audio input speech has been tentatively recognized.

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

Syntax

'Declaration

Example

The example below shows the subscription of an anonymous method as a handler for SpeechHypothesized, which in turn calls a display function (DisplayResult) to return to the user interface the best candidate and the list of alternates generated.

_recognizer.SpeechHypothesized +=
delegate(object sender, SpeechHypothesizedEventArgs eventArgs) {

    Utils.DisplayAudioInputFormat(_audioStateLabel, _recognizer);
            DisplayResult(eventArgs);
};

// Displays the semantics, rules, and alternates of the result.
private void DisplayResult(EventArgs eventArgs) {

    //Make sure We handle different event types we support
     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) {
//If eventArgs not null repopulate displays
//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);
        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);
        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);
        Utils.DisplaySemanticsSML(_recognitionSmlBrowser, result);
        Utils.DisplaySemanticsTreeView(_semanticsTreeView, result.Semantics);
        break;
    default:
        _bestCandidateTextBox.ForeColor = Color.Black;
        break;
}

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

    }
}

Remarks

Handlers of SpeechHypothesized events can obtain the best possible hypothesis phrase through an instance of the RecognitionResult object returned by the Result property of the SpeechHypothesizedEventArgs object passed to the handler. (SpeechHypothesizedEventArgs is derived fromSpeechRecognitionEventArgs)).

Handlling of SpeechHypothesized is not typically required in production running, but is useful when debugging grammars.

Platforms

Development Platforms

Windows XP Professional with Service Pack 2 (SP2), Windows Server 2003, Windows Vista Ultimate Edition, Windows Vista Business Edition, Windows Vista Enterprise Edition

Target Platforms

See Also

Reference

SpeechRecognitionEngine Class
SpeechRecognitionEngine Members
Microsoft.Speech.Recognition Namespace
SpeechRecognitionEngine Class
RecognitionEventArgs Class
SpeechHypothesizedEventArgs Class
SpeechRecognitionEngine.SpeechDetected Event
SpeechRecognitionRejected