共用方式為


RecognizerUpdateReachedEventArgs 類別

定義

RecognizerUpdateReachedRecognizerUpdateReached 事件傳回資料。

public ref class RecognizerUpdateReachedEventArgs : EventArgs
public class RecognizerUpdateReachedEventArgs : EventArgs
type RecognizerUpdateReachedEventArgs = class
    inherit EventArgs
Public Class RecognizerUpdateReachedEventArgs
Inherits EventArgs
繼承
RecognizerUpdateReachedEventArgs

範例

下列範例顯示載入和卸載 Grammar 物件的主控台應用程式。 應用程式會 RequestRecognizerUpdate 使用 方法來要求語音辨識引擎暫停,以便接收更新。 應用程式接著會載入或卸載 Grammar 物件。

在每個更新中,事件的處理常式 SpeechRecognitionEngine.RecognizerUpdateReached 會將目前載入 Grammar 物件的名稱和狀態寫入主控台。 當載入和卸載文法時,應用程式會先辨識伺服器陣列動物的名稱、伺服器陣列動物的名稱和動物的名稱,然後只辨識植物的名稱。

using System;  
using System.Speech.Recognition;  
using System.Collections.Generic;  
using System.Threading;  

namespace SampleRecognition  
{  
  class Program  
  {  
    private static SpeechRecognitionEngine recognizer;  
    public static void Main(string[] args)  
    {  

      // Initialize an in-process speech recognition engine and configure its input.  
      using (recognizer = new SpeechRecognitionEngine(new System.Globalization.CultureInfo("en-US")))  
      {  
        recognizer.SetInputToDefaultAudioDevice();  

        // Create the first grammar - Farm.  
        Choices animals = new Choices(new string[] { "cow", "pig", "goat" });  
        GrammarBuilder farm = new GrammarBuilder(animals);  
        Grammar farmAnimals = new Grammar(farm);  
        farmAnimals.Name = "Farm";  

        // Create the second grammar - Fruit.  
        Choices fruit = new Choices(new string[] { "apples", "peaches", "oranges" });  
        GrammarBuilder favorite = new GrammarBuilder(fruit);  
        Grammar favoriteFruit = new Grammar(favorite);  
        favoriteFruit.Name = "Fruit";  

        // Attach event handlers.  
        recognizer.SpeechRecognized +=  
          new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);  
        recognizer.RecognizerUpdateReached +=  
          new EventHandler<RecognizerUpdateReachedEventArgs>(recognizer_RecognizerUpdateReached);  
        recognizer.SpeechRecognitionRejected +=  
          new EventHandler<SpeechRecognitionRejectedEventArgs>(recognizer_SpeechRecognitionRejected);  

        // Load the Farm grammar.  
        recognizer.LoadGrammar(farmAnimals);  

        // Start asynchronous, continuous recognition.  
        recognizer.RecognizeAsync(RecognizeMode.Multiple);  
        Console.WriteLine("Starting asynchronous, continuous recognition");  
        Console.WriteLine("  Farm grammar is loaded and enabled.");  

        // Pause to recognize farm animals.  
        Thread.Sleep(7000);  
        Console.WriteLine();  

        // Request an update and load the Fruit grammar.  
        recognizer.RequestRecognizerUpdate();  
        recognizer.LoadGrammarAsync(favoriteFruit);  
        Thread.Sleep(7000);  

        // Request an update and unload the Farm grammar.  
        recognizer.RequestRecognizerUpdate();  
        recognizer.UnloadGrammar(farmAnimals);  
        Thread.Sleep(7000);  
      }  

      // Keep the console window open.  
      Console.WriteLine();  
      Console.WriteLine("Press any key to exit...");  
      Console.ReadKey();  
    }  

    // At the update, get the names and enabled status of the currently loaded grammars.  
    public static void recognizer_RecognizerUpdateReached(  
      object sender, RecognizerUpdateReachedEventArgs e)  
    {  
      Console.WriteLine();  
      Console.WriteLine("Update reached:");  
      Thread.Sleep(1000);  

      string qualifier;  
      List<Grammar> grammars = new List<Grammar>(recognizer.Grammars);  
      foreach (Grammar g in grammars)  
      {  
        qualifier = (g.Enabled) ? "enabled" : "disabled";  
        Console.WriteLine("  {0} grammar is loaded and {1}.",  
        g.Name, qualifier);  
      }  
    }  

    // Write the text of the recognized phrase to the console.  
    static void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)  
    {  
      Console.WriteLine("    Speech recognized: " + e.Result.Text);  
    }  

    // Write a message to the console when recognition fails.  
    static void recognizer_SpeechRecognitionRejected(object sender, SpeechRecognitionRejectedEventArgs e)  
    {  
      Console.WriteLine("    Recognition attempt failed");  
    }  
  }  
}  

備註

RecognizerUpdateReached 事件提供暫停語音辨識引擎的機制,以套用不可部分完成和同步的修改,例如載入和卸載文法。

如果您的應用程式使用 SpeechRecognitionEngine 實例來管理辨識,它可以使用其中 SpeechRecognitionEngine.RequestRecognizerUpdate 一種方法來要求引擎暫停以接收更新。 SpeechRecognitionEngine實例在準備好進行更新時引發 SpeechRecognitionEngine.RecognizerUpdateReached 事件。

SpeechRecognitionEngine當實例暫停時,您可以載入、卸載、啟用和停用 Grammar 物件,以及修改 、 InitialSilenceTimeoutEndSilenceTimeout 屬性的值 BabbleTimeout

如果您的應用程式使用 SpeechRecognizer 實例來管理辨識,它可以使用其中 SpeechRecognizer.RequestRecognizerUpdate 一種方法來要求引擎暫停以接收更新。 SpeechRecognizer實例在準備好進行更新時引發 SpeechRecognizer.RecognizerUpdateReached 事件。

SpeechRecognizer當實例暫停時,您可以載入、卸載、啟用和停用 Grammar 物件。

處理 SpeechRecognitionEngine.RecognizerUpdateReachedSpeechRecognizer.RecognizerUpdateReached 事件時,辨識引擎會暫停,直到事件處理常式傳回為止。

RecognizerUpdateReachedEventArgs 衍生自 EventArgs

屬性

AudioPosition

取得與事件相關聯的音訊位置。

UserToken

UserToken取得應用程式呼叫 RequestRecognizerUpdateRequestRecognizerUpdate 時傳遞至系統的 。

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於

另請參閱