SpeechRecognitionEngine.LoadGrammar(Grammar) SpeechRecognitionEngine.LoadGrammar(Grammar) SpeechRecognitionEngine.LoadGrammar(Grammar) Method


Grammar オブジェクトを同期的に読み込みます。Synchronously loads a Grammar object.

 void LoadGrammar(System::Speech::Recognition::Grammar ^ grammar);
public void LoadGrammar (System.Speech.Recognition.Grammar grammar);
member this.LoadGrammar : System.Speech.Recognition.Grammar -> unit


Grammar Grammar Grammar

読み込む文法オブジェクト。The grammar object to load.


Grammarnullです。Grammar is null.

Grammar が有効な状態ではありません。Grammar is not in a valid state.

次の例では、基本的な音声認識を示すコンソール アプリケーションの一部を示します。The following example shows part of a console application that demonstrates basic speech recognition. 例は、作成、DictationGrammar音声認識エンジンに読み込みます。The example creates a DictationGrammar and loads it into a speech recognizer.

using System;  
using System.Speech.Recognition;  

namespace SpeechRecognitionApp  
  class Program  
    static void Main(string[] args)  

      // Create an in-process speech recognizer for the en-US locale.  
      using (  
      SpeechRecognitionEngine recognizer =  
        new SpeechRecognitionEngine(  
          new System.Globalization.CultureInfo("en-US")))  

        // Create and load a dictation grammar.  
        recognizer.LoadGrammar(new DictationGrammar());  

        // Add a handler for the speech recognized event.  
        recognizer.SpeechRecognized +=   
          new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);  

        // Configure input to the speech recognizer.  

        // Start asynchronous, continuous speech recognition.  

        // Keep the console window open.  
        while (true)  

    // Handle the SpeechRecognized event.  
    static void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)  
      Console.WriteLine("Recognized text: " + e.Result.Text);  


場合に、認識エンジンが例外をスロー、Grammarオブジェクトが既に読み込まれて、非同期的に読み込みまたはをすべて認識エンジンに読み込めませんでした。The recognizer throws an exception if the Grammar object is already loaded, is being asynchronously loaded, or has failed to load into any recognizer. 同じを読み込むことができませんGrammarオブジェクトの複数のインスタンスにSpeechRecognitionEngineします。You cannot load the same Grammar object into multiple instances of SpeechRecognitionEngine. 代わりに、作成、新しいGrammarオブジェクトごとにSpeechRecognitionEngineインスタンス。Instead, create a new Grammar object for each SpeechRecognitionEngine instance.

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

文法を読み込むときに、既定で有効です。When you load a grammar, it is enabled by default. 読み込む文法を無効にするには、Enabledプロパティ。To disable a loaded grammar, use the Enabled property.

読み込み、Grammar非同期的にオブジェクトを使用して、LoadGrammarAsyncメソッド。To load a Grammar object asynchronously, use the LoadGrammarAsync method.