SpeechRecognitionRejectedEventArgs 类

定义

提供有关 SpeechRecognitionRejectedSpeechRecognitionRejected 事件的信息。

public ref class SpeechRecognitionRejectedEventArgs : System::Speech::Recognition::RecognitionEventArgs
public class SpeechRecognitionRejectedEventArgs : System.Speech.Recognition.RecognitionEventArgs
[System.Serializable]
public class SpeechRecognitionRejectedEventArgs : System.Speech.Recognition.RecognitionEventArgs
type SpeechRecognitionRejectedEventArgs = class
    inherit RecognitionEventArgs
[<System.Serializable>]
type SpeechRecognitionRejectedEventArgs = class
    inherit RecognitionEventArgs
Public Class SpeechRecognitionRejectedEventArgs
Inherits RecognitionEventArgs
继承
SpeechRecognitionRejectedEventArgs
属性

示例

以下示例识别诸如“显示爵士乐类别中的艺术家列表”或“显示专辑福音”等短语。 当语音输入无法与语法内容匹配时,该示例使用 事件的处理程序 SpeechRecognitionRejected 在控制台中显示通知,并具有足够的置信度,从而生成成功的识别。

using System;  
using System.Speech.Recognition;  

namespace SampleRecognition  
{  
  class Program  
  {  
    static void Main(string[] args)  

    // Initialize a shared speech recognition engine.  
    {  
      using (SpeechRecognizer recognizer =  
         new SpeechRecognizer())  
      {  

        // Create a grammar.  
        //  Create lists of alternative choices.  
        Choices listTypes = new Choices(new string[] { "albums", "artists" });  
        Choices genres = new Choices(new string[] {   
          "blues", "classical", "gospel", "jazz", "rock" });  

        //  Create a GrammarBuilder object and assemble the grammar components.  
        GrammarBuilder mediaMenu = new GrammarBuilder("Display");  
        mediaMenu.Append("the list of", 0, 1);  
        mediaMenu.Append(listTypes);  
        mediaMenu.Append("in the", 0, 1);  
        mediaMenu.Append(genres);  
        mediaMenu.Append("category", 0, 1);  

        //  Build a Grammar object from the GrammarBuilder.  
        Grammar mediaMenuGrammar = new Grammar(mediaMenu);  
        mediaMenuGrammar.Name = "Media Chooser";  

        // Attach event handlers.  
        recognizer.LoadGrammarCompleted +=  
          new EventHandler<LoadGrammarCompletedEventArgs>(recognizer_LoadGrammarCompleted);  
        recognizer.SpeechRecognized +=  
          new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);  
        recognizer.SpeechRecognitionRejected +=   
          new EventHandler<SpeechRecognitionRejectedEventArgs>(recognizer_SpeechRecognitionRejected);  

        // Load the grammar object to the recognizer.  
        recognizer.LoadGrammarAsync(mediaMenuGrammar);  

        // Keep the console window open.  
        Console.ReadLine();  
      }  
    }  

    // Handle the SpeechRecognitionRejected event.  
    static void recognizer_SpeechRecognitionRejected(object sender, SpeechRecognitionRejectedEventArgs e)  
    {  
      Console.WriteLine("Speech input was rejected.");  
      foreach (RecognizedPhrase phrase in e.Result.Alternates)  
      {  
        Console.WriteLine("  Rejected phrase: " + phrase.Text);  
        Console.WriteLine("  Confidence score: " + phrase.Confidence);  
      }  
    }  

    // Handle the LoadGrammarCompleted event.  
    static void recognizer_LoadGrammarCompleted(object sender, LoadGrammarCompletedEventArgs e)  
    {  
      Console.WriteLine("Grammar loaded: " + e.Grammar.Name);  
    }  

    // Handle the SpeechRecognized event.  
    static void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)  
    {  
      Console.WriteLine("Speech recognized: " + e.Result.Text);  
    }  
  }  
}  

注解

事件 SpeechRecognitionRejectedSpeechRecognizerSpeechRecognitionEngine 类引发。

SpeechRecognitionRejected 事件由语音识别引擎生成,当识别操作中的替代项都没有足够高的置信度分数被接受时。 可通过 Result 属性获取有关被拒绝短语的详细信息。

SpeechRecognitionRejectedEventArgs 派生自 RecognitionEventArgs

属性

Result

获取与语音识别事件关联的识别结果数据。

(继承自 RecognitionEventArgs)

方法

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

返回表示当前对象的字符串。

(继承自 Object)

适用于

另请参阅