Grammar.SpeechRecognized イベント

定義

音声認識エンジンが Grammar オブジェクトを使用して認識を実行すると発生します。

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

イベントの種類

次の例は、 Grammar オブジェクトの SpeechRecognized イベントにイベント ハンドラーを使用する方法を示しています。 認識結果がコンソールに出力 されます

public partial class Form1 : Form
{
  SpeechRecognitionEngine sre;

  public Form1()
  {
  InitializeComponent();

  // Create an in-process speech recognizer.
  sre = new SpeechRecognitionEngine();

  // Configure input to the speech recognizer.
  sre.SetInputToDefaultAudioDevice();

  // Create a simple grammar and load it.
  Grammar testGrammar = new Grammar(new GrammarBuilder("testing"));
  sre.LoadGrammarAsync(testGrammar);

  // Add a handler for the grammar's speech recognized event.
  testGrammar.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(testGrammar_SpeechRecognized);

  // Start asynchronous speech recognition.
  sre.RecognizeAsync();
  }

  // Handle the grammar's SpeechRecognized event, output the recognized text.
  void testGrammar_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
  {
    Console.WriteLine("Recognized text: " + e.Result.Text);
  }
}

注釈

音声認識エンジンは、入力を認識すると SpeechRecognized イベントも発生します。 Grammar オブジェクトのSpeechRecognized イベントは、音声認識エンジンのSpeechRecognized イベントの前に発生します。 詳細については、 SpeechRecognizer.SpeechRecognizedSpeechRecognitionEngine.SpeechRecognized、および RecognizeCompleted イベントを参照してください。

特定の文法に固有のタスクは、常に、 Grammar オブジェクトの SpeechRecognized イベントのハンドラーによって処理される必要があります。

適用対象

こちらもご覧ください