SpeechRecognizedEventArgs 类

定义

SpeechRecognizedSpeechRecognizedSpeechRecognized 事件提供信息。Provides information for the SpeechRecognized, SpeechRecognized, and SpeechRecognized events.

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

示例

下面的示例是一个控制台应用程序的一部分, 该应用程序加载语音识别语法, 并演示了到共享识别器的语音输入、关联的识别结果和语音识别器引发的相关事件。The following example is part of a console application that loads a speech recognition grammar and demonstrates speech input to the shared recognizer, the associated recognition results, and the associated events raised by the speech recognizer. 如果 Windows 语音识别未运行, 则启动此应用程序也将启动 Windows 语音识别。If Windows Speech Recognition is not running, then starting this application will also start Windows Speech Recognition.

"我想要飞入到迈阿密" 之类的朗读输入将触发SpeechRecognized事件。Spoken input such as "I want to fly from Chicago to Miami" will trigger a SpeechRecognized event. 说到 "从休斯顿到芝加哥飞入" 这一SpeechRecognized短语不会触发事件。Speaking the phrase "Fly me from Houston to Chicago " will not trigger a SpeechRecognized event.

该示例使用SpeechRecognized事件的处理程序显示已成功识别的短语以及它们在控制台中包含的语义。The example uses a handler for the SpeechRecognized event to display successfully recognized phrases and the semantics they contain in the console.

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 SemanticResultValue objects that contain cities and airport codes.  
        SemanticResultValue chicago = new SemanticResultValue("Chicago", "ORD");  
        SemanticResultValue boston = new SemanticResultValue("Boston", "BOS");  
        SemanticResultValue miami = new SemanticResultValue("Miami", "MIA");  
        SemanticResultValue dallas = new SemanticResultValue("Dallas", "DFW");  
  
        // Create a Choices object and add the SemanticResultValue objects, using  
        // implicit conversion from SemanticResultValue to GrammarBuilder  
        Choices cities = new Choices();  
        cities.Add(new Choices(new GrammarBuilder[] { chicago, boston, miami, dallas }));  
  
        // Build the phrase and add SemanticResultKeys.  
        GrammarBuilder chooseCities = new GrammarBuilder();  
        chooseCities.Append("I want to fly from");  
        chooseCities.Append(new SemanticResultKey("origin", cities));  
        chooseCities.Append("to");  
        chooseCities.Append(new SemanticResultKey("destination", cities));  
  
        // Build a Grammar object from the GrammarBuilder.  
        Grammar bookFlight = new Grammar(chooseCities);  
        bookFlight.Name = "Book Flight";  
  
        // Add a handler for the LoadGrammarCompleted event.  
        recognizer.LoadGrammarCompleted +=  
          new EventHandler<LoadGrammarCompletedEventArgs>(recognizer_LoadGrammarCompleted);  
  
        // Add a handler for the SpeechRecognized event.  
        recognizer.SpeechRecognized +=   
          new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);  
  
        // Load the grammar object to the recognizer.  
        recognizer.LoadGrammarAsync(bookFlight);  
  
        // Keep the console window open.  
        Console.ReadLine();  
      }  
    }  
  
    // Handle the LoadGrammarCompleted event.  
    static void recognizer_LoadGrammarCompleted(object sender, LoadGrammarCompletedEventArgs e)  
    {  
      Console.WriteLine("Grammar loaded: " + e.Grammar.Name);  
      Console.WriteLine();  
    }  
  
    // Handle the SpeechRecognized event.  
    static void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)  
    {  
      Console.WriteLine("Speech recognized:  " + e.Result.Text);  
      Console.WriteLine();  
      Console.WriteLine("Semantic results:");  
      Console.WriteLine("  The flight origin is " + e.Result.Semantics["origin"].Value);  
      Console.WriteLine("  The flight destination is " + e.Result.Semantics["destination"].Value);  
    }  
  }  
}  
  

注解

SpeechRecognized 事件Grammar由、SpeechRecognizer和类SpeechRecognitionEngine引发。A SpeechRecognized event is raised by the Grammar, SpeechRecognizer and SpeechRecognitionEngine classes.

SpeechRecognized当识别操作的一个或多个备用项具有足够高的置信度得分时, 将生成事件。SpeechRecognized events are generated when one or more of the alternates from a recognition operation have a high enough confidence score to be accepted. 若要获取有关识别的短语的详细信息, Result请访问事件处理程序中的属性。To obtain detailed information about a recognized phrase, access the Result property in the handler for the event.

SpeechRecognizedEventArgs派生自RecognitionEventArgs类。SpeechRecognizedEventArgs derives from the RecognitionEventArgs class.

属性

Result

获取与语音识别事件关联的识别结果数据。Gets the recognition result data associated with the speech recognition event.

(继承自 RecognitionEventArgs)

方法

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)

适用于

另请参阅