SpeechRecognitionEngine.RecognizeAsync SpeechRecognitionEngine.RecognizeAsync SpeechRecognitionEngine.RecognizeAsync SpeechRecognitionEngine.RecognizeAsync Method

定義

非同期音声認識操作を開始します。Starts an asynchronous speech recognition operation.

オーバーロード

RecognizeAsync() RecognizeAsync() RecognizeAsync() RecognizeAsync()

単一の非同期音声認識操作を実行します。Performs a single, asynchronous speech recognition operation.

RecognizeAsync(RecognizeMode) RecognizeAsync(RecognizeMode) RecognizeAsync(RecognizeMode) RecognizeAsync(RecognizeMode)

1 つ以上の非同期音声認識操作を実行します。Performs one or more asynchronous speech recognition operations.

注釈

これらのメソッド実行の 1 つまたは複数の非同期認識操作。These methods perform single or multiple, asynchronous recognition operations. 認識エンジンは、その読み込み済みで有効になっている音声認識文法に対する各操作を実行します。The recognizer performs each operation against its loaded and enabled speech recognition grammars.

このメソッドの呼び出し中に、認識エンジンは、次のイベントを発生させることができます。During a call to this method, the recognizer can raise the following events:

非同期認識操作の結果を取得するには、認識エンジンのイベント ハンドラーを結び付けるSpeechRecognizedイベント。To retrieve the result of an asynchronous recognition operation, attach an event handler to the recognizer's SpeechRecognized event. 認識エンジンは、同期または非同期認識操作を正常に完了するたびに、このイベントを発生させます。The recognizer raises this event whenever it successfully completes a synchronous or asynchronous recognition operation. 認識が、失敗した場合、ResultプロパティRecognizeCompletedEventArgsのハンドラーにアクセスできる、オブジェクト、RecognizeCompletedイベントになりますnullします。If recognition was not successful, the Result property on RecognizeCompletedEventArgs object, which you can access in the handler for the RecognizeCompleted event, will be null.

次の理由で非同期認識操作を実行できます。An asynchronous recognition operation can fail for the following reasons:

RecognizeAsync() RecognizeAsync() RecognizeAsync() RecognizeAsync()

単一の非同期音声認識操作を実行します。Performs a single, asynchronous speech recognition operation.

public:
 void RecognizeAsync();
public void RecognizeAsync ();
member this.RecognizeAsync : unit -> unit
Public Sub RecognizeAsync ()

次の例では、基本的な非同期音声認識を示すコンソール アプリケーションの一部を示します。The following example shows part of a console application that demonstrates basic asynchronous speech recognition. 例は、作成、DictationGrammarインプロセス音声認識エンジンに読み込みますや、1 つの非同期認識操作を実行します。The example creates a DictationGrammar, loads it into an in-process speech recognizer, and performs one asynchronous recognition operation. イベント ハンドラーは、認識エンジンが操作中に発生するイベントを示すために含まれています。Event handlers are included to demonstrate the events that the recognizer raises during the operation.

using System;  
using System.Globalization;  
using System.Speech.Recognition;  
using System.Threading;  

namespace AsynchronousRecognition  
{  
  class Program  
  {  
    // Indicate whether asynchronous recognition is complete.  
    static bool completed;  

    static void Main(string[] args)  
    {  
      // Create an in-process speech recognizer.  
      using (SpeechRecognitionEngine recognizer =  
        new SpeechRecognitionEngine(new CultureInfo("en-US")))  
      {  
        // Create a grammar for choosing cities for a flight.  
        Choices cities = new Choices(new string[]   
        { "Los Angeles", "New York", "Chicago", "San Francisco", "Miami", "Dallas" });  

        GrammarBuilder gb = new GrammarBuilder();  
        gb.Append("I want to fly from");  
        gb.Append(cities);  
        gb.Append("to");  
        gb.Append(cities);  

        // Construct a Grammar object and load it to the recognizer.  
        Grammar cityChooser = new Grammar(gb);  
        cityChooser.Name = ("City Chooser");  
        recognizer.LoadGrammarAsync(cityChooser);  

        // Attach event handlers.  
        recognizer.SpeechDetected +=  
          new EventHandler<SpeechDetectedEventArgs>(  
            SpeechDetectedHandler);  
        recognizer.SpeechHypothesized +=  
          new EventHandler<SpeechHypothesizedEventArgs>(  
            SpeechHypothesizedHandler);  
        recognizer.SpeechRecognitionRejected +=  
          new EventHandler<SpeechRecognitionRejectedEventArgs>(  
            SpeechRecognitionRejectedHandler);  
        recognizer.SpeechRecognized +=  
          new EventHandler<SpeechRecognizedEventArgs>(  
            SpeechRecognizedHandler);  
        recognizer.RecognizeCompleted +=  
          new EventHandler<RecognizeCompletedEventArgs>(  
            RecognizeCompletedHandler);  

        // Assign input to the recognizer and start an asynchronous  
        // recognition operation.  
        recognizer.SetInputToDefaultAudioDevice();  

        completed = false;  
        Console.WriteLine("Starting asynchronous recognition...");  
        recognizer.RecognizeAsync();  

        // Wait for the operation to complete.  
        while (!completed)  
        {  
          Thread.Sleep(333);  
        }  
        Console.WriteLine("Done.");  
      }  

      Console.WriteLine();  
      Console.WriteLine("Press any key to exit...");  
      Console.ReadKey();  
    }  

    // Handle the SpeechDetected event.  
    static void SpeechDetectedHandler(object sender, SpeechDetectedEventArgs e)  
    {  
      Console.WriteLine(" In SpeechDetectedHandler:");  
      Console.WriteLine(" - AudioPosition = {0}", e.AudioPosition);  
    }  

    // Handle the SpeechHypothesized event.  
    static void SpeechHypothesizedHandler(  
      object sender, SpeechHypothesizedEventArgs e)  
    {  
      Console.WriteLine(" In SpeechHypothesizedHandler:");  

      string grammarName = "<not available>";  
      string resultText = "<not available>";  
      if (e.Result != null)  
      {  
        if (e.Result.Grammar != null)  
        {  
          grammarName = e.Result.Grammar.Name;  
        }  
        resultText = e.Result.Text;  
      }  

      Console.WriteLine(" - Grammar Name = {0}; Result Text = {1}",  
        grammarName, resultText);  
    }  

    // Handle the SpeechRecognitionRejected event.  
    static void SpeechRecognitionRejectedHandler(  
      object sender, SpeechRecognitionRejectedEventArgs e)  
    {  
      Console.WriteLine(" In SpeechRecognitionRejectedHandler:");  

      string grammarName = "<not available>";  
      string resultText = "<not available>";  
      if (e.Result != null)  
      {  
        if (e.Result.Grammar != null)  
        {  
          grammarName = e.Result.Grammar.Name;  
        }  
        resultText = e.Result.Text;  
      }  

      Console.WriteLine(" - Grammar Name = {0}; Result Text = {1}",  
        grammarName, resultText);  
    }  

    // Handle the SpeechRecognized event.  
    static void SpeechRecognizedHandler(  
      object sender, SpeechRecognizedEventArgs e)  
    {  
      Console.WriteLine(" In SpeechRecognizedHandler.");  

      string grammarName = "<not available>";  
      string resultText = "<not available>";  
      if (e.Result != null)  
      {  
        if (e.Result.Grammar != null)  
        {  
          grammarName = e.Result.Grammar.Name;  
        }  
        resultText = e.Result.Text;  
      }  

      Console.WriteLine(" - Grammar Name = {0}; Result Text = {1}",  
        grammarName, resultText);  
    }  

    // Handle the RecognizeCompleted event.  
    static void RecognizeCompletedHandler(  
      object sender, RecognizeCompletedEventArgs e)  
    {  
      Console.WriteLine(" In RecognizeCompletedHandler.");  

      if (e.Error != null)  
      {  
        Console.WriteLine(  
          " - Error occurred during recognition: {0}", e.Error);  
        return;  
      }  
      if (e.InitialSilenceTimeout || e.BabbleTimeout)  
      {  
        Console.WriteLine(  
          " - BabbleTimeout = {0}; InitialSilenceTimeout = {1}",  
          e.BabbleTimeout, e.InitialSilenceTimeout);  
        return;  
      }  
      if (e.InputStreamEnded)  
      {  
        Console.WriteLine(  
          " - AudioPosition = {0}; InputStreamEnded = {1}",  
          e.AudioPosition, e.InputStreamEnded);  
      }  
      if (e.Result != null)  
      {  
        Console.WriteLine(  
          " - Grammar = {0}; Text = {1}; Confidence = {2}",  
          e.Result.Grammar.Name, e.Result.Text, e.Result.Confidence);  
        Console.WriteLine(" - AudioPosition = {0}", e.AudioPosition);  
      }  
      else  
      {  
        Console.WriteLine(" - No result.");  
      }  

      completed = true;  
    }  
  }  
}  

注釈

このメソッドは、1 つの非同期認識操作を実行します。This method performs a single, asynchronous recognition operation. 認識エンジンは、その読み込み済みで有効になっている音声認識文法に対する操作を実行します。The recognizer performs the operation against its loaded and enabled speech recognition grammars.

このメソッドの呼び出し中に、認識エンジンは、次のイベントを発生させることができます。During a call to this method, the recognizer can raise the following events:

非同期認識操作の結果を取得するには、認識エンジンのイベント ハンドラーを結び付けるSpeechRecognizedイベント。To retrieve the result of an asynchronous recognition operation, attach an event handler to the recognizer's SpeechRecognized event. 認識エンジンは、同期または非同期認識操作を正常に完了するたびに、このイベントを発生させます。The recognizer raises this event whenever it successfully completes a synchronous or asynchronous recognition operation. 認識が、失敗した場合、ResultプロパティRecognizeCompletedEventArgsのハンドラーにアクセスできる、オブジェクト、RecognizeCompletedイベントになりますnullします。If recognition was not successful, the Result property on RecognizeCompletedEventArgs object, which you can access in the handler for the RecognizeCompleted event, will be null.

同期の認識を実行するには、いずれかを使用、Recognizeメソッド。To perform synchronous recognition, use one of the Recognize methods.

こちらもご覧ください

RecognizeAsync(RecognizeMode) RecognizeAsync(RecognizeMode) RecognizeAsync(RecognizeMode) RecognizeAsync(RecognizeMode)

1 つ以上の非同期音声認識操作を実行します。Performs one or more asynchronous speech recognition operations.

public:
 void RecognizeAsync(System::Speech::Recognition::RecognizeMode mode);
public void RecognizeAsync (System.Speech.Recognition.RecognizeMode mode);
member this.RecognizeAsync : System.Speech.Recognition.RecognizeMode -> unit
Public Sub RecognizeAsync (mode As RecognizeMode)

パラメーター

mode
RecognizeMode RecognizeMode RecognizeMode RecognizeMode

1 つまたは複数の認識操作を実行するかどうかを示します。Indicates whether to perform one or multiple recognition operations.

次の例では、基本的な非同期音声認識を示すコンソール アプリケーションの一部を示します。The following example shows part of a console application that demonstrates basic asynchronous speech recognition. 例は、作成、DictationGrammarインプロセス音声認識エンジンに読み込みますや、複数の非同期認識操作を実行します。The example creates a DictationGrammar, loads it into an in-process speech recognizer, and performs multiple asynchronous recognition operations. 30 秒後に、非同期操作が取り消されました。The asynchronous operations are cancelled after 30 seconds. イベント ハンドラーは、認識エンジンが操作中に発生するイベントを示すために含まれています。Event handlers are included to demonstrate the events that the recognizer raises during the operation.

using System;  
using System.Globalization;  
using System.Speech.Recognition;  
using System.Threading;  

namespace AsynchronousRecognition  
{  
  class Program  
  {  
    // Indicate whether asynchronous recognition is complete.  
    static bool completed;  

    static void Main(string[] args)  
    {  
      // Create an in-process speech recognizer.  
      using (SpeechRecognitionEngine recognizer =  
        new SpeechRecognitionEngine(new CultureInfo("en-US")))  
      {  
        // Create a grammar for choosing cities for a flight.  
        Choices cities = new Choices(new string[] { "Los Angeles", "New York", "Chicago", "San Francisco", "Miami", "Dallas" });  

        GrammarBuilder gb = new GrammarBuilder();  
        gb.Append("I want to fly from");  
        gb.Append(cities);  
        gb.Append("to");  
        gb.Append(cities);  

        // Construct a Grammar object and load it to the recognizer.  
        Grammar cityChooser = new Grammar(gb);  
        cityChooser.Name = ("City Chooser");  
        recognizer.LoadGrammarAsync(cityChooser);  

        // Attach event handlers.  
        recognizer.SpeechDetected +=  
          new EventHandler<SpeechDetectedEventArgs>(  
            SpeechDetectedHandler);  
        recognizer.SpeechHypothesized +=  
          new EventHandler<SpeechHypothesizedEventArgs>(  
            SpeechHypothesizedHandler);  
        recognizer.SpeechRecognitionRejected +=  
          new EventHandler<SpeechRecognitionRejectedEventArgs>(  
            SpeechRecognitionRejectedHandler);  
        recognizer.SpeechRecognized +=  
          new EventHandler<SpeechRecognizedEventArgs>(  
            SpeechRecognizedHandler);  
        recognizer.RecognizeCompleted +=  
          new EventHandler<RecognizeCompletedEventArgs>(  
            RecognizeCompletedHandler);  

        // Assign input to the recognizer and start asynchronous  
        // recognition.  
        recognizer.SetInputToDefaultAudioDevice();  

        completed = false;  
        Console.WriteLine("Starting asynchronous recognition...");  
        recognizer.RecognizeAsync(RecognizeMode.Multiple);  

        // Wait 30 seconds, and then cancel asynchronous recognition.  
        Thread.Sleep(TimeSpan.FromSeconds(30));  
        recognizer.RecognizeAsyncCancel();  

        // Wait for the operation to complete.  
        while (!completed)  
        {  
          Thread.Sleep(333);  
        }  
        Console.WriteLine("Done.");  
      }  

      Console.WriteLine();  
      Console.WriteLine("Press any key to exit...");  
      Console.ReadKey();  
    }  

    // Handle the SpeechDetected event.  
    static void SpeechDetectedHandler(object sender, SpeechDetectedEventArgs e)  
    {  
      Console.WriteLine(" In SpeechDetectedHandler:");  
      Console.WriteLine(" - AudioPosition = {0}", e.AudioPosition);  
    }  

    // Handle the SpeechHypothesized event.  
    static void SpeechHypothesizedHandler(  
      object sender, SpeechHypothesizedEventArgs e)  
    {  
      Console.WriteLine(" In SpeechHypothesizedHandler:");  

      string grammarName = "<not available>";  
      string resultText = "<not available>";  
      if (e.Result != null)  
      {  
        if (e.Result.Grammar != null)  
        {  
          grammarName = e.Result.Grammar.Name;  
        }  
        resultText = e.Result.Text;  
      }  

      Console.WriteLine(" - Grammar Name = {0}; Result Text = {1}",  
        grammarName, resultText);  
    }  

    // Handle the SpeechRecognitionRejected event.  
    static void SpeechRecognitionRejectedHandler(  
      object sender, SpeechRecognitionRejectedEventArgs e)  
    {  
      Console.WriteLine(" In SpeechRecognitionRejectedHandler:");  

      string grammarName = "<not available>";  
      string resultText = "<not available>";  
      if (e.Result != null)  
      {  
        if (e.Result.Grammar != null)  
        {  
          grammarName = e.Result.Grammar.Name;  
        }  
        resultText = e.Result.Text;  
      }  

      Console.WriteLine(" - Grammar Name = {0}; Result Text = {1}",  
        grammarName, resultText);  
    }  

    // Handle the SpeechRecognized event.  
    static void SpeechRecognizedHandler(  
      object sender, SpeechRecognizedEventArgs e)  
    {  
      Console.WriteLine(" In SpeechRecognizedHandler.");  

      string grammarName = "<not available>";  
      string resultText = "<not available>";  
      if (e.Result != null)  
      {  
        if (e.Result.Grammar != null)  
        {  
          grammarName = e.Result.Grammar.Name;  
        }  
        resultText = e.Result.Text;  
      }  

      Console.WriteLine(" - Grammar Name = {0}; Result Text = {1}",  
        grammarName, resultText);  
    }  

    // Handle the RecognizeCompleted event.  
    static void RecognizeCompletedHandler(  
      object sender, RecognizeCompletedEventArgs e)  
    {  
      Console.WriteLine(" In RecognizeCompletedHandler.");  

      if (e.Error != null)  
      {  
        Console.WriteLine(  
          " - Error occurred during recognition: {0}", e.Error);  
        return;  
      }  
      if (e.InitialSilenceTimeout || e.BabbleTimeout)  
      {  
        Console.WriteLine(  
          " - BabbleTimeout = {0}; InitialSilenceTimeout = {1}",  
          e.BabbleTimeout, e.InitialSilenceTimeout);  
        return;  
      }  
      if (e.InputStreamEnded)  
      {  
        Console.WriteLine(  
          " - AudioPosition = {0}; InputStreamEnded = {1}",  
          e.AudioPosition, e.InputStreamEnded);  
      }  
      if (e.Result != null)  
      {  
        Console.WriteLine(  
          " - Grammar = {0}; Text = {1}; Confidence = {2}",  
          e.Result.Grammar.Name, e.Result.Text, e.Result.Confidence);  
        Console.WriteLine(" - AudioPosition = {0}", e.AudioPosition);  
      }  
      else  
      {  
        Console.WriteLine(" - No result.");  
      }  

      completed = true;  
    }  
  }  
}  

注釈

場合modeMultiple、認識エンジンの続行まで非同期認識操作を実行する、RecognizeAsyncCancelまたはRecognizeAsyncStopメソッドが呼び出されます。If mode is Multiple, the recognizer continues performing asynchronous recognition operations until the RecognizeAsyncCancel or RecognizeAsyncStop method is called.

このメソッドの呼び出し中に、認識エンジンは、次のイベントを発生させることができます。During a call to this method, the recognizer can raise the following events:

非同期認識操作の結果を取得するには、認識エンジンのイベント ハンドラーを結び付けるSpeechRecognizedイベント。To retrieve the result of an asynchronous recognition operation, attach an event handler to the recognizer's SpeechRecognized event. 認識エンジンは、同期または非同期認識操作を正常に完了するたびに、このイベントを発生させます。The recognizer raises this event whenever it successfully completes a synchronous or asynchronous recognition operation. 認識が、失敗した場合、ResultプロパティRecognizeCompletedEventArgsのハンドラーにアクセスできる、オブジェクト、RecognizeCompletedイベントになりますnullします。If recognition was not successful, the Result property on RecognizeCompletedEventArgs object, which you can access in the handler for the RecognizeCompleted event, will be null.

次の理由で非同期認識操作を実行できます。An asynchronous recognition operation can fail for the following reasons:

  • タイムアウト間隔は、の有効期限が切れる前に、音声が検出されない、BabbleTimeoutまたはInitialSilenceTimeoutプロパティ。Speech is not detected before the timeout intervals expire for the BabbleTimeout or InitialSilenceTimeout properties.

  • 認識エンジンが音声を検出するが読み込み済みで有効になっているのいずれかで一致が検出されないGrammarオブジェクト。The recognition engine detects speech but finds no matches in any of its loaded and enabled Grammar objects.

同期の認識を実行するには、いずれかを使用、Recognizeメソッド。To perform synchronous recognition, use one of the Recognize methods.

こちらもご覧ください

適用対象