SpeechRecognizer.AudioStateChanged SpeechRecognizer.AudioStateChanged SpeechRecognizer.AudioStateChanged SpeechRecognizer.AudioStateChanged Event

定義

オーディオの状態変化が認識機能によって受け取られると発生します。Occurs when the state changes in the audio being received by the recognizer.

public:
 event EventHandler<System::Speech::Recognition::AudioStateChangedEventArgs ^> ^ AudioStateChanged;
public event EventHandler<System.Speech.Recognition.AudioStateChangedEventArgs> AudioStateChanged;
member this.AudioStateChanged : EventHandler<System.Speech.Recognition.AudioStateChangedEventArgs> 
Public Custom Event AudioStateChanged As EventHandler(Of AudioStateChangedEventArgs) 

次の例では、 AudioStateChangedイベントのハンドラーを使用AudioStateして、列挙AudioState体のメンバーを使用して変更するたびに、レコグナイザーの新しいをコンソールに書き込みます。The following example uses a handler for the AudioStateChanged event to write the recognizer's new AudioState to the console each time it changes using a member of the AudioState enumeration.

using System;  
using System.Speech.Recognition;  

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

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

        // Create and load a grammar.  
        Grammar dictation = new DictationGrammar();  
        dictation.Name = "Dictation Grammar";  
        recognizer.LoadGrammar(dictation);  

        // Attach event handlers.  
        recognizer.AudioStateChanged +=  
          new EventHandler<AudioStateChangedEventArgs>(recognizer_AudioStateChanged);  
        recognizer.SpeechRecognized +=  
          new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);  
        recognizer.StateChanged +=  
          new EventHandler<StateChangedEventArgs>(recognizer_StateChanged);  

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

    // Handle the AudioStateChanged event.  
    static void recognizer_AudioStateChanged(object sender, AudioStateChangedEventArgs e)  
    {  
      Console.WriteLine("The new audio state is: " + e.AudioState);  
    }  

    // Handle the SpeechRecognized event.  
    static void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)  
    {  
      if (e.Result != null && e.Result.Text != null)  
      {  
        Console.WriteLine();  
        Console.WriteLine("  Recognized text =  {0}", e.Result.Text);  
        Console.WriteLine();  
      }  
      else  
      {  
        Console.WriteLine("  Recognized text not available.");  
      }  

      Console.WriteLine();  
      Console.WriteLine("Done.");  
      Console.WriteLine();  
      Console.WriteLine("Press any key to exit...");  
      Console.ReadKey();  
    }  

    // Put the recognizer into Listening mode.  
    static void recognizer_StateChanged(object sender, StateChangedEventArgs e)  
    {  
      if (e.RecognizerState != RecognizerState.Stopped)  
      {  
        Console.WriteLine();  
        recognizer.EmulateRecognizeAsync("Start listening");  
      }  
    }  
  }  
}  

注釈

イベント時にオーディオの状態を取得するには、関連付けAudioStateられているAudioStateChangedEventArgsのプロパティを使用します。To get the audio state at the time of the event, use the AudioState property of the associated AudioStateChangedEventArgs. 認識エンジンへの入力の現在のオーディオの状態を取得するには、 AudioStateレコグナイザーのプロパティを使用します。To get the current audio state of the input to the recognizer, use the recognizer's AudioState property. オーディオ状態の詳細については、 AudioState 「列挙体」を参照してください。For more information about audio state, see the AudioState enumeration.

AudioStateChangedイベントのデリゲートを作成する場合は、イベントを処理するメソッドを指定します。When you create a delegate for an AudioStateChanged event, you identify the method that will handle the event. イベントをイベント ハンドラーに関連付けるには、デリゲートのインスタンスをイベントに追加します。To associate the event with your event handler, add an instance of the delegate to the event. デリゲートを削除しない限り、そのイベントが発生すると常にイベント ハンドラーが呼び出されます。The event handler is called whenever the event occurs, unless you remove the delegate. イベントハンドラーデリゲートの詳細については、「イベントとデリゲート」を参照してください。For more information about event-handler delegates, see Events and Delegates.

適用対象

こちらもご覧ください