SpeechRecognitionEngine.SpeechRecognized イベント
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
読み込まれ、有効になっているSpeechRecognitionEngineオブジェクトのいずれかに一致する入力を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 オブジェクトを構築し、それを SpeechRecognitionEngine に読み込んで認識を実行するコンソール アプリケーションの一部です。 この例では、 SpeechRecognitionEngineへの音声入力、関連する認識結果、音声認識エンジンによって発生する関連イベントを示します。
"シカゴからマイアミに飛びたい" などの音声入力によって、 SpeechRecognized イベントがトリガーされます。 「ヒューストンからシカゴに飛んで」というフレーズを話すと、 SpeechRecognized イベントはトリガーされません。
この例では、 SpeechRecognized イベントのハンドラーを使用して、正常に認識されたフレーズと、コンソールに含まれるセマンティクスを表示します。
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 SemanticResultValue objects that contain cities and airport codes.
SemanticResultValue chicago = new SemanticResultValue("Chicago", "ORD");
SemanticResultValue boston = new SemanticResultValue("Boston", "BOS");
SemanticResultValue miami = new SemanticResultValue("Miami", "MIA");
SemanticResultValue dallas = new SemanticResultValue("Dallas", "DFW");
// Create a Choices object and add the SemanticResultValue objects, using
// implicit conversion from SemanticResultValue to GrammarBuilder
Choices cities = new Choices();
cities.Add(new Choices(new GrammarBuilder[] { chicago, boston, miami, dallas }));
// Build the phrase and add SemanticResultKeys.
GrammarBuilder chooseCities = new GrammarBuilder();
chooseCities.Append("I want to fly from");
chooseCities.Append(new SemanticResultKey("origin", cities));
chooseCities.Append("to");
chooseCities.Append(new SemanticResultKey("destination", cities));
// Build a Grammar object from the GrammarBuilder.
Grammar bookFlight = new Grammar(chooseCities);
bookFlight.Name = "Book Flight";
// Add a handler for the LoadGrammarCompleted event.
recognizer.LoadGrammarCompleted +=
new EventHandler<LoadGrammarCompletedEventArgs>(recognizer_LoadGrammarCompleted);
// Add a handler for the SpeechRecognized event.
recognizer.SpeechRecognized +=
new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);
// Load the grammar object to the recognizer.
recognizer.LoadGrammarAsync(bookFlight);
// Set the input to the recognizer.
recognizer.SetInputToDefaultAudioDevice();
// Start recognition.
recognizer.RecognizeAsync();
// Keep the console window open.
Console.ReadLine();
}
}
// Handle the LoadGrammarCompleted event.
static void recognizer_LoadGrammarCompleted(object sender, LoadGrammarCompletedEventArgs e)
{
Console.WriteLine("Grammar loaded: " + e.Grammar.Name);
Console.WriteLine();
}
// Handle the SpeechRecognized event.
static void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
Console.WriteLine("Speech recognized: " + e.Result.Text);
Console.WriteLine();
Console.WriteLine("Semantic results:");
Console.WriteLine(" The flight origin is " + e.Result.Semantics["origin"].Value);
Console.WriteLine(" The flight destination is " + e.Result.Semantics["destination"].Value);
}
}
}
注釈
Recognizeメソッドまたは RecognizeAsync メソッドのいずれかを使用して、認識操作を開始できます。 認識エンジンは、入力が読み込まれたGrammarオブジェクトの 1 つと一致し、認識を構成するのに十分な信頼度を持つと判断した場合、SpeechRecognized イベントを発生させます。 ResultのSpeechRecognitionRejectedEventArgs プロパティには、受け入れられたRecognitionResult オブジェクトが含まれています。 SpeechRecognized イベントのハンドラーは、認識されたフレーズと、信頼度スコアの低い認識Alternatesの一覧を取得できます。
アプリケーションで SpeechRecognitionEngine インスタンスを使用している場合は、 UpdateRecognizerSetting のいずれかの方法で音声入力が受け入れられるか拒否されるかの信頼度レベルを変更できます。 BabbleTimeout、InitialSilenceTimeout、EndSilenceTimeout、およびEndSilenceTimeoutAmbiguousのプロパティを使用して、音声認識が非音声入力に応答する方法を変更できます。
認識エンジンが文法に一致する入力を受け取ると、 Grammar オブジェクトは SpeechRecognized イベントを発生させることができます。 Grammar オブジェクトのSpeechRecognized イベントは、音声認識エンジンのSpeechRecognized イベントの前に発生します。 特定の文法に固有のタスクは、常に SpeechRecognized イベントのハンドラーによって実行する必要があります。
SpeechRecognized デリゲートを作成するときは、イベントを処理するメソッドを識別します。 イベントをイベント ハンドラーに関連付けるには、デリゲートのインスタンスをイベントに追加します。 デリゲートを削除しない限り、イベントが発生するたびにイベント ハンドラーが呼び出されます。