SpeechRecognitionEngine.SpeechHypothesized イベント


SpeechRecognitionEngine が文法の複数の完全な語句のコンポーネントである可能性がある単語を認識した場合に発生します。Raised when the SpeechRecognitionEngine has recognized a word or words that may be a component of multiple complete phrases in a grammar.

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



次の例では、"ジャズカテゴリのアーティストの一覧を表示する" などの語句を認識しています。The following example recognizes phrases such as "Display the list of artists in the jazz category". この例では、イベントを使用して、認識されたときに、 SpeechHypothesized 不完全な語句フラグメントをコンソールに表示します。The example uses the SpeechHypothesized event to display incomplete phrase fragments in the console as they are recognized.

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.  
        //  Create lists of alternative choices.  
        Choices listTypes = new Choices(new string[] { "albums", "artists" });  
        Choices genres = new Choices(new string[] {   
          "blues", "classical", "gospel", "jazz", "rock" });  

        //  Create a GrammarBuilder object and assemble the grammar components.  
        GrammarBuilder mediaMenu = new GrammarBuilder("Display the list of");  
        mediaMenu.Append("in the");  

        //  Build a Grammar object from the GrammarBuilder.  
        Grammar mediaMenuGrammar = new Grammar(mediaMenu);  
        mediaMenuGrammar.Name = "Media Chooser";  

        // Attach event handlers.  
        recognizer.LoadGrammarCompleted +=  
          new EventHandler<LoadGrammarCompletedEventArgs>(recognizer_LoadGrammarCompleted);  
        recognizer.SpeechRecognized +=  
          new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);  
        recognizer.SpeechHypothesized +=  
          new EventHandler<SpeechHypothesizedEventArgs>(recognizer_SpeechHypothesized);  

        // Load the grammar object to the recognizer.  

        // Set the input to the recognizer.  

        // Start asynchronous recognition.  

        // Keep the console window open.  

    // Handle the SpeechHypothesized event.  
    static void recognizer_SpeechHypothesized(object sender, SpeechHypothesizedEventArgs e)  
      Console.WriteLine("Speech hypothesized: " + e.Result.Text);  

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


は、 SpeechRecognitionEngine SpeechHypothesized 入力語句を識別しようとしたときに多数のイベントを生成します。The SpeechRecognitionEngine generates numerous SpeechHypothesized events as it attempts to identify an input phrase. Resultイベントのハンドラーで、オブジェクトのプロパティで部分的に認識された語句のテキストにアクセスでき SpeechHypothesizedEventArgs SpeechHypothesized ます。You can access the text of partially recognized phrases in the Result property of the SpeechHypothesizedEventArgs object in the handler for the SpeechHypothesized event. 通常、これらのイベントの処理はデバッグにのみ役立ちます。Typically, handling these events is useful only for debugging.

SpeechHypothesizedEventArgs は、RecognitionEventArgs から派生します。SpeechHypothesizedEventArgs derives from RecognitionEventArgs.

詳細については、プロパティ、、、、およびの各メソッドを参照してください EndSilenceTimeoutAmbiguous Recognize RecognizeAsync EmulateRecognize EmulateRecognizeAsyncFor more information see the EndSilenceTimeoutAmbiguous property and the Recognize, RecognizeAsync, EmulateRecognize, and EmulateRecognizeAsync methods.

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