次の方法で共有


SpeechRecognizer.SpeechHypothesized イベント

定義

認識機能が文法の複数の完全な語句のコンポーネントである可能性がある単語を認識した場合に発生します。

public:
 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) 

イベントの種類

次の例では、"ジャズ カテゴリのアーティストの一覧を表示する" などの語句を認識します。 この例では、 イベントを SpeechHypothesized 使用して、認識された不完全なフレーズ フラグメントをコンソールに表示します。

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 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(listTypes);
        mediaMenu.Append("in the");
        mediaMenu.Append(genres);
        mediaMenu.Append("category.");

        //  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.
        recognizer.LoadGrammarAsync(mediaMenuGrammar);

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

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

注釈

共有認識エンジンは、入力があいまいな場合にこのイベントを発生させることができます。 たとえば、"新しいゲームしてください" または "新しいゲーム" の認識をサポートする音声認識文法の場合、"新しいゲームしてください" は明確な入力であり、"新しいゲーム" はあいまいな入力です。

イベントのデリゲート SpeechHypothesized を作成するときは、イベントを処理するメソッドを特定します。 イベント ハンドラーにイベントを関連付けるには、イベントにデリゲートのインスタンスを追加します。 イベント ハンドラーは、デリゲートを削除しない限り、イベントが発生するたびに呼び出されます。 イベント ハンドラー デリゲートの詳細については、「 イベントとデリゲート」を参照してください。

適用対象

こちらもご覧ください