This documentation is archived and is not being maintained.

SpeechRecognizer.SpeechRecognitionRejected Event

The event raised when the recognition engine detects speech, but can only return candidate phrases with low confidence levels.

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

public event EventHandler<SpeechRecognitionRejectedEventArgs> SpeechRecognitionRejected
/** @event */
public void add_SpeechRecognitionRejected (EventHandler<SpeechRecognitionRejectedEventArgs> value)

/** @event */
public void remove_SpeechRecognitionRejected (EventHandler<SpeechRecognitionRejectedEventArgs> value)

In JScript, you can handle the events defined by a class, but you cannot define your own.
Not applicable.

Handlers of SpeechRecognitionRejected events can obtain the best possible candidate phrase, as well as a list of up to MaxAlternates phrases with lower confidence levels through an instance of the RecognitionResult object returned by the Result property of the SpeechRecognitionRejectedEventArgs object passed to the handler. (SpeechRecognitionRejectedEventArgs is derived fromSpeechRecognitionEventArgs)).

The confidence level cut off for recognition is an arbitrary feature of any particular recognition engine and is not settable by applications.

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


								_recognizer.SpeechRecognitionRejected +=
    delegate(object sender, SpeechRecognitionRejectedEventArgs eventArgs) {
Utils.DisplayAudioInputFormat(_audioStateLabel, _recognizer);
Utils.DisplayRecognizerState(_recognizerStateLabel, _recognizer.State);
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 "System.Speech.Recognition.SpeechHypothesizedEventArgs":
        _bestCandidateTextBox.ForeColor = Color.Black;
        _bestCandidateTextBox.Text = result.Text;
        _phraseInfoLabel.Text = null;
        break;
    case "System.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 "System.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 "System.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");

    }
}

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0
Show: