SpeechRecognitionEngine.SpeechDetected SpeechRecognitionEngine.SpeechDetected SpeechRecognitionEngine.SpeechDetected SpeechRecognitionEngine.SpeechDetected Event

定義

SpeechRecognitionEngine が音声として識別できる入力を検出すると発生します。Raised when the SpeechRecognitionEngine detects input that it can identify as speech.

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

次の例は、フライトの発信元と送信先の市区町村を選択するためのコンソールアプリケーションの一部です。The following example is part of a console application for choosing origin and destination cities for a flight. アプリケーションでは、"マイアミからシカゴに向けて飛ぶことができます" などの語句を認識します。The application recognizes phrases such as "I want to fly from Miami to Chicago." この例ではSpeechDetected 、イベントを使用AudioPositionして、音声が検出されるたびにを報告します。The example uses the SpeechDetected event to report the AudioPosition each time speech is detected.

using System;  
using System.Speech.Recognition;  

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

    // Initialize an in-process speech recognition engine.  
    {  
      using (SpeechRecognitionEngine recognizer =  
         new SpeechRecognitionEngine())  
      {  

        // Create a grammar.  
        Choices cities = new Choices(new string[] {   
          "Los Angeles", "New York", "Chicago", "San Francisco", "Miami", "Dallas" });  

        GrammarBuilder gb = new GrammarBuilder();  
        gb.Append("I would like to fly from");  
        gb.Append(cities);  
        gb.Append("to");  
        gb.Append(cities);  

        // Create a Grammar object and load it to the recognizer.  
        Grammar g = new Grammar(gb);  
        g.Name = ("City Chooser");  
        recognizer.LoadGrammarAsync(g);  

        // Attach event handlers.  
        recognizer.LoadGrammarCompleted +=  
          new EventHandler<LoadGrammarCompletedEventArgs>(recognizer_LoadGrammarCompleted);  
        recognizer.SpeechDetected +=  
          new EventHandler<SpeechDetectedEventArgs>(recognizer_SpeechDetected);  
        recognizer.SpeechRecognized +=  
          new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);  

        // Set the input to the recognizer.  
        recognizer.SetInputToDefaultAudioDevice();  

        // Start recognition.  
        recognizer.RecognizeAsync();  

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

    // Handle the SpeechDetected event.  
    static void recognizer_SpeechDetected(object sender, SpeechDetectedEventArgs e)  
    {  
      Console.WriteLine("  Speech detected at AudioPosition = {0}", e.AudioPosition);  
    }  

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

注釈

各音声認識エンジンには、無音と音声を区別するためのアルゴリズムが用意されています。Each speech recognizer has an algorithm to distinguish between silence and speech. SpeechRecognitionEngine音声認識操作を実行すると、そのアルゴリズムSpeechDetectedが音声として入力を識別すると、イベントが発生します。When the SpeechRecognitionEngine performs a speech recognition operation, it raises the SpeechDetected event when its algorithm identifies the input as speech. 関連付けAudioPositionられSpeechDetectedEventArgsたオブジェクトのプロパティは、認識エンジンが音声を検出した入力ストリーム内の位置を示します。The AudioPosition property of the associated SpeechDetectedEventArgs object indicates location in the input stream where the recognizer detected speech. SpeechRecognitionEngine 、、 SpeechDetected SpeechRecognized、のいずれSpeechHypothesizedSpeechRecognitionRejectedのイベントを発生させる前に、イベントを発生させます。The SpeechRecognitionEngine raises the SpeechDetected event before it raises any of the SpeechHypothesized, SpeechRecognized, or SpeechRecognitionRejected events.

詳細についてはRecognize EmulateRecognizeRecognizeAsync「」、 EmulateRecognizeAsync 「」、「」、および「」を参照してください。For more information see the Recognize, RecognizeAsync, EmulateRecognize, and EmulateRecognizeAsync methods.

SpeechDetected デリゲートを作成する場合は、イベントを処理するメソッドを指定します。When you create a SpeechDetected delegate, 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.

適用対象

こちらもご覧ください