SpeechRecognizedEventArgs 类

定义

SpeechRecognizedSpeechRecognizedSpeechRecognized 事件提供信息。

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

示例

以下示例是控制台应用程序的一部分,该应用程序加载语音识别语法,并演示共享识别器语音输入、关联的识别结果以及语音识别器引发的关联事件。 如果 Windows 语音识别未运行,则启动此应用程序也会启动 Windows 语音识别。

口述输入(如“我想从芝加哥飞往迈阿密”)将触发事件 SpeechRecognized 。 说“把我从休斯顿飞到芝加哥”这句话不会引发 SpeechRecognized 事件。

该示例使用 事件的处理程序 SpeechRecognized 来显示成功识别的短语及其在控制台中包含的语义。

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);  
    }  
  }  
}  

注解

事件 SpeechRecognizedGrammarSpeechRecognizerSpeechRecognitionEngine 类引发。

SpeechRecognized 当识别操作中的一个或多个备用项具有足够高的置信度分数以接受时,将生成事件。 若要获取有关已识别短语的详细信息,请在 事件的处理程序中访问 Result 属性。

SpeechRecognizedEventArgs 派生自 RecognitionEventArgs 类。

属性

Result

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

(继承自 RecognitionEventArgs)

方法

Equals(Object)

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

(继承自 Object)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

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

(继承自 Object)

适用于

另请参阅