SpeechRecognitionEngine.LoadGrammarCompleted SpeechRecognitionEngine.LoadGrammarCompleted SpeechRecognitionEngine.LoadGrammarCompleted SpeechRecognitionEngine.LoadGrammarCompleted Event


SpeechRecognitionEngineGrammar オブジェクトの非同期読み込みを終了するときに発生します。Raised when the SpeechRecognitionEngine finishes the asynchronous loading of a Grammar object.

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

次の例では、インプロセス音声認識エンジンを作成し、文法および自由発話のディクテーションを受け入れるための特定の単語を認識するための 2 種類が作成されます。The following example creates an in-process speech recognizer, and then creates two types of grammars for recognizing specific words and for accepting free dictation. 例では、構築、Grammarオブジェクトから完成した音声認識文法の各種し非同期的に読み込みます、GrammarオブジェクトをSpeechRecognitionEngineインスタンス。The example constructs a Grammar object from each of the completed speech recognition grammars, then asynchronously loads the Grammar objects to the SpeechRecognitionEngine instance. ハンドラーを認識エンジンのLoadGrammarCompletedSpeechRecognizedイベントでは、名前をコンソールに書き込み、Grammarを認識し、認識結果のテキストをそれぞれ実行に使用されたオブジェクト。Handlers for the recognizer's LoadGrammarCompleted and SpeechRecognized events write to the console the name of the Grammar object that was used to perform the recognition and the text of the recognition result, respectively.

using System;  
using System.Speech.Recognition;  

namespace SampleRecognition  
  class Program  
    private static SpeechRecognitionEngine recognizer;  
    public static void Main(string[] args)  

      // Initialize an in-process speech recognition engine and set its input.  
      recognizer = new SpeechRecognitionEngine();  

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

      // Create the "yesno" grammar.  
      Choices yesChoices = new Choices(new string[] { "yes", "yup", "yeah" });  
      SemanticResultValue yesValue =  
          new SemanticResultValue(yesChoices, (bool)true);  
      Choices noChoices = new Choices(new string[] { "no", "nope", "neah" });  
      SemanticResultValue noValue =  
          new SemanticResultValue(noChoices, (bool)false);  
      SemanticResultKey yesNoKey =  
          new SemanticResultKey("yesno", new Choices(new GrammarBuilder[] { yesValue, noValue }));  
      Grammar yesnoGrammar = new Grammar(yesNoKey);  
      yesnoGrammar.Name = "yesNo";  

      // Create the "done" grammar.  
      Grammar doneGrammar =  
        new Grammar(new Choices(new string[] { "done", "exit", "quit", "stop" }));  
      doneGrammar.Name = "Done";  

      // Create a dictation grammar.  
      Grammar dictation = new DictationGrammar();  
      dictation.Name = "Dictation";  

      // Load grammars to the recognizer.  

      // Start asynchronous, continuous recognition.  

      // Keep the console window open.  

    // Handle the LoadGrammarCompleted event.   
    static void recognizer_LoadGrammarCompleted(object sender, LoadGrammarCompletedEventArgs e)  
      string grammarName = e.Grammar.Name;  
      bool grammarLoaded = e.Grammar.Loaded;  

      if (e.Error != null)  
        Console.WriteLine("LoadGrammar for {0} failed with a {1}.",  
        grammarName, e.Error.GetType().Name);  

        // Add exception handling code here.  

      Console.WriteLine("Grammar {0} {1} loaded.",  
      grammarName, (grammarLoaded) ? "is" : "is not");  

    // Handle the SpeechRecognized event.  
    static void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)  
      Console.WriteLine("Grammar({0}): {1}", e.Result.Grammar.Name, e.Result.Text);  

      // Add event handler code here.  


認識エンジンのLoadGrammarAsyncメソッドが非同期操作を開始します。The recognizer's LoadGrammarAsync method initiates an asynchronous operation. SpeechRecognitionEngine操作が完了すると、このイベントを発生させます。The SpeechRecognitionEngine raises this event when it completes the operation. 取得する、Grammar認識エンジンが読み込まれているオブジェクト、 Grammar 、関連付けられているプロパティLoadGrammarCompletedEventArgsします。To get the Grammar object that the recognizer loaded, use the Grammar property of the associated LoadGrammarCompletedEventArgs. 現在の取得にGrammar認識エンジンが読み込まれて、オブジェクトを使用して、認識エンジンのGrammarsプロパティ。To get the current Grammar objects the recognizer has loaded, use the recognizer's Grammars property.

認識エンジンが実行されている場合、アプリケーションが使用する必要がありますRequestRecognizerUpdateを読み込み、アンロードが有効にすると、または文法を無効にする前に、音声認識エンジンを一時停止します。If the recognizer is running, applications must use RequestRecognizerUpdate to pause the speech recognition engine before loading, unloading, enabling, or disabling a grammar.

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