SpeechRecognitionEngine.EmulateRecognizeAsync メソッド

定義

非同期音声認識に音声ではなくテキストを使用して、音声認識エンジンに対する入力をエミュレートします。

オーバーロード

EmulateRecognizeAsync(String)

非同期音声認識に音声ではなくテキストを使用して、音声認識エンジンに対する語句の入力をエミュレートします。

EmulateRecognizeAsync(RecognizedWordUnit[], CompareOptions)

非同期音声認識にオーディオではなく RecognizedWordUnit の配列を使用して、共有された音声認識エンジンに対する特定の語の入力をエミュレートし、語と読み込まれている音声認識文法との間で認識エンジンが Unicode 比較をどのように行うかを指定します。

EmulateRecognizeAsync(String, CompareOptions)

非同期音声認識にオーディオではなくテキストを使用して、音声認識エンジンに対するフレーズの入力をエミュレートし、フレーズと読み込まれている音声認識文法との間で認識エンジンが Unicode 比較をどのように行うかを指定します。

注釈

これらのメソッドは、システム オーディオ入力をバイパスし、オブジェクトまたはオブジェクトのRecognizedWordUnit配列としてString認識エンジンにテキストを提供します。 これは、アプリケーションまたは文法をテストまたはデバッグする場合に役立ちます。 たとえば、エミュレーションを使用して、単語が文法に含まれているかどうか、および単語が認識されたときに返されるセマンティクスを判断できます。 エミュレーション操作中に SetInputToNull 音声認識エンジンへのオーディオ入力を無効にするには、 メソッドを使用します。

音声認識エンジンは、認識操作が SpeechDetectedエミュレートされていないかのように、、 SpeechHypothesizedSpeechRecognitionRejected、および SpeechRecognized イベントを発生させます。 認識エンジンは、非同期認識操作を完了すると、 イベントを EmulateRecognizeCompleted 発生させます。 認識エンジンは、改行と余分な空白を無視し、句読点をリテラル入力として扱います。

Note

RecognitionResultエミュレートされた入力に応答して音声認識エンジンによって生成されるオブジェクトのプロパティの値nullAudioは です。

同期認識をエミュレートするには、 メソッドを使用します EmulateRecognize

EmulateRecognizeAsync(String)

非同期音声認識に音声ではなくテキストを使用して、音声認識エンジンに対する語句の入力をエミュレートします。

public:
 void EmulateRecognizeAsync(System::String ^ inputText);
public void EmulateRecognizeAsync (string inputText);
member this.EmulateRecognizeAsync : string -> unit
Public Sub EmulateRecognizeAsync (inputText As String)

パラメーター

inputText
String

認識操作の入力。

例外

認識エンジンに、読み込まれている音声認識文法がないか、認識エンジンに、未完了の非同期認識操作が存在しています。

inputTextnullです。

inputText が空の文字列 ("") です。

次のコード例は、非同期エミュレートされた入力、関連する認識結果、および音声認識エンジンによって発生する関連イベントを示すコンソール アプリケーションの一部です。 この例では、次の出力が生成されます。

TestRecognizeAsync("Smith")...  
 SpeechDetected event raised.  
 SpeechRecognized event raised.  
  Grammar = Smith; Text = Smith  
 EmulateRecognizeCompleted event raised.  
  Grammar = Smith; Text = Smith  
 Done.  

TestRecognizeAsync("Jones")...  
 SpeechDetected event raised.  
 SpeechRecognized event raised.  
  Grammar = Jones; Text = Jones  
 EmulateRecognizeCompleted event raised.  
  Grammar = Jones; Text = Jones  
 Done.  

TestRecognizeAsync("Mister")...  
 SpeechDetected event raised.  
 SpeechHypothesized event raised.  
  Grammar = Smith; Text = mister  
 SpeechRecognitionRejected event raised.  
  Grammar = <not available>; Text =  
 EmulateRecognizeCompleted event raised.  
  No recognition result available.  
 Done.  

TestRecognizeAsync("Mister Smith")...  
 SpeechDetected event raised.  
 SpeechRecognized event raised.  
  Grammar = Smith; Text = mister Smith  
 EmulateRecognizeCompleted event raised.  
  Grammar = Smith; Text = mister Smith  
 Done.  

press any key to exit...  
using System;  
using System.Globalization;  
using System.Speech.Recognition;  
using System.Threading;  

namespace SreEmulateRecognizeAsync  
{  
  class Program  
  {  
    // Indicate when an asynchronous operation is finished.  
    static bool completed;  

    static void Main(string[] args)  
    {  
      using (SpeechRecognitionEngine recognizer =  
        new SpeechRecognitionEngine(new CultureInfo("en-US")))  
      {  
        // Load grammars.  
        recognizer.LoadGrammar(CreateNameGrammar("Smith"));  
        recognizer.LoadGrammar(CreateNameGrammar("Jones"));  

        // Configure the audio input.  
        recognizer.SetInputToNull();  

        // Add event handlers for the events raised by the  
        // EmulateRecognizeAsync method.  
        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.EmulateRecognizeCompleted +=  
          new EventHandler<EmulateRecognizeCompletedEventArgs>(  
            EmulateRecognizeCompletedHandler);  

        // Start four asynchronous emulated recognition operations.  
        TestRecognizeAsync(recognizer, "Smith");  
        TestRecognizeAsync(recognizer, "Jones");  
        TestRecognizeAsync(recognizer, "Mister");  
        TestRecognizeAsync(recognizer, "Mister Smith");  
      }  

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

    // Create a simple name grammar.  
    // Set the grammar name to the surname.  
    private static Grammar CreateNameGrammar(string surname)  
    {  
      GrammarBuilder builder = new GrammarBuilder("mister", 0, 1);  
      builder.Append(surname);  

      Grammar nameGrammar = new Grammar(builder);  
      nameGrammar.Name = surname;  

      return nameGrammar;  
    }  

    // Send emulated input to the recognizer for asynchronous  
    // recognition.  
    private static void TestRecognizeAsync(  
      SpeechRecognitionEngine recognizer, string input)  
    {  
      completed = false;  

      Console.WriteLine("TestRecognizeAsync(\"{0}\")...", input);  
      recognizer.EmulateRecognizeAsync(input);  

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

      Console.WriteLine(" Done.");  
      Console.WriteLine();  
    }  

    static void SpeechDetectedHandler(  
      object sender, SpeechDetectedEventArgs e)  
    {  
      Console.WriteLine(" SpeechDetected event raised.");  
    }  

    static void SpeechHypothesizedHandler(  
      object sender, SpeechHypothesizedEventArgs e)  
    {  
      Console.WriteLine(" SpeechHypothesized event raised.");  
      if (e.Result != null)  
      {  
        Console.WriteLine("  Grammar = {0}; Text = {1}",  
          e.Result.Grammar.Name ?? "<none>", e.Result.Text);  
      }  
      else  
      {  
        Console.WriteLine("  No recognition result available.");  
      }  
    }  

    // Handle events.  
    static void SpeechRecognitionRejectedHandler(  
      object sender, SpeechRecognitionRejectedEventArgs e)  
    {  
      Console.WriteLine(" SpeechRecognitionRejected event raised.");  
      if (e.Result != null)  
      {  
        string grammarName;  
        if (e.Result.Grammar != null)  
        {  
          grammarName = e.Result.Grammar.Name ?? "<none>";  
        }  
        else  
        {  
          grammarName = "<not available>";  
        }  
        Console.WriteLine("  Grammar = {0}; Text = {1}",  
          grammarName, e.Result.Text);  
      }  
      else  
      {  
        Console.WriteLine("  No recognition result available.");  
      }  
    }  

    static void SpeechRecognizedHandler(  
      object sender, SpeechRecognizedEventArgs e)  
    {  
      Console.WriteLine(" SpeechRecognized event raised.");  
      if (e.Result != null)  
      {  
        Console.WriteLine("  Grammar = {0}; Text = {1}",  
          e.Result.Grammar.Name ?? "<none>", e.Result.Text );  
      }  
      else  
      {  
        Console.WriteLine("  No recognition result available.");  
      }  
    }  

    static void EmulateRecognizeCompletedHandler(  
      object sender, EmulateRecognizeCompletedEventArgs e)  
    {  
      Console.WriteLine(" EmulateRecognizeCompleted event raised.");  

      if (e.Error != null)  
      {  
        Console.WriteLine("  {0} exception encountered: {1}:",  
          e.Error.GetType().Name, e.Error.Message);  
      }  
      else if (e.Cancelled)  
      {  
        Console.WriteLine("  Operation cancelled.");  
      }  
      else if (e.Result != null)  
      {  
        Console.WriteLine("  Grammar = {0}; Text = {1}",  
          e.Result.Grammar.Name ?? "<none>", e.Result.Text);  
      }  
      else  
      {  
        Console.WriteLine("  No recognition result available.");  
      }  

      completed = true;  
    }  
  }  
}

注釈

音声認識エンジンは、認識操作が SpeechDetectedエミュレートされていないかのように、、 SpeechHypothesizedSpeechRecognitionRejected、および SpeechRecognized イベントを発生させます。 認識エンジンは、非同期認識操作を完了すると、 イベントを EmulateRecognizeCompleted 発生させます。

Vista および Windows 7 に付属する認識エンジンは、入力フレーズに文法規則を適用するときに、大文字と小文字と文字の幅を無視します。 この種類の比較の詳細については、列挙値OrdinalIgnoreCaseIgnoreWidthCompareOptions参照してください。 認識エンジンは、新しい行と余分な空白も無視し、句読点をリテラル入力として扱います。

このメソッドは、メソッドの同期例外がスローできる非使用例外をすべて返すタスクに格納します。 返されたタスクに例外が格納されている場合、その例外はタスクが待機されたときにスローされます。 などの ArgumentException使用例外は、引き続き同期的にスローされます。 格納されている例外については、 によって EmulateRecognize(String)スローされる例外に関するページを参照してください。

こちらもご覧ください

適用対象

EmulateRecognizeAsync(RecognizedWordUnit[], CompareOptions)

非同期音声認識にオーディオではなく RecognizedWordUnit の配列を使用して、共有された音声認識エンジンに対する特定の語の入力をエミュレートし、語と読み込まれている音声認識文法との間で認識エンジンが Unicode 比較をどのように行うかを指定します。

public:
 void EmulateRecognizeAsync(cli::array <System::Speech::Recognition::RecognizedWordUnit ^> ^ wordUnits, System::Globalization::CompareOptions compareOptions);
public void EmulateRecognizeAsync (System.Speech.Recognition.RecognizedWordUnit[] wordUnits, System.Globalization.CompareOptions compareOptions);
member this.EmulateRecognizeAsync : System.Speech.Recognition.RecognizedWordUnit[] * System.Globalization.CompareOptions -> unit
Public Sub EmulateRecognizeAsync (wordUnits As RecognizedWordUnit(), compareOptions As CompareOptions)

パラメーター

wordUnits
RecognizedWordUnit[]

認識操作のための必要を格納する単語単位の配列。

compareOptions
CompareOptions

エミュレートされた認識操作に使用する比較の種類を示す列挙値のビットごとの組み合わせ。

例外

認識エンジンに、読み込まれている音声認識文法がないか、認識エンジンに、未完了の非同期認識操作が存在しています。

wordUnitsnullです。

wordUnits は 1 つ以上の null 要素を含みます。

compareOptionsIgnoreNonSpaceIgnoreSymbols、または StringSort フラグを含みます。

注釈

音声認識エンジンは、認識操作が SpeechDetectedエミュレートされていないかのように、、 SpeechHypothesizedSpeechRecognitionRejected、および SpeechRecognized イベントを発生させます。 認識エンジンは、非同期認識操作を完了すると、 イベントを EmulateRecognizeCompleted 発生させます。

認識エンジンは、入力フレーズに文法規則を適用するときに使用 compareOptions します。 Vista および Windows 7 に付属する認識エンジンは、 または IgnoreCase 値が存在する場合、大文字と小文字をOrdinalIgnoreCase区別します。 認識エンジンは常に文字幅を無視し、かな型は無視しません。 認識エンジンは、新しい行と余分な空白も無視し、句読点をリテラル入力として扱います。 文字幅とかな型の詳細については、 列挙を CompareOptions 参照してください。

このメソッドは、メソッドの同期例外がスローできる非使用例外をすべて返すタスクに格納します。 返されたタスクに例外が格納されている場合、その例外はタスクが待機されたときにスローされます。 などの ArgumentException使用例外は、引き続き同期的にスローされます。 格納されている例外については、 によって EmulateRecognize(RecognizedWordUnit[], CompareOptions)スローされる例外に関するページを参照してください。

こちらもご覧ください

適用対象

EmulateRecognizeAsync(String, CompareOptions)

非同期音声認識にオーディオではなくテキストを使用して、音声認識エンジンに対するフレーズの入力をエミュレートし、フレーズと読み込まれている音声認識文法との間で認識エンジンが Unicode 比較をどのように行うかを指定します。

public:
 void EmulateRecognizeAsync(System::String ^ inputText, System::Globalization::CompareOptions compareOptions);
public void EmulateRecognizeAsync (string inputText, System.Globalization.CompareOptions compareOptions);
member this.EmulateRecognizeAsync : string * System.Globalization.CompareOptions -> unit
Public Sub EmulateRecognizeAsync (inputText As String, compareOptions As CompareOptions)

パラメーター

inputText
String

認識操作の入力語句。

compareOptions
CompareOptions

エミュレートされた認識操作に使用する比較の種類を示す列挙値のビットごとの組み合わせ。

例外

認識エンジンに、読み込まれている音声認識文法がないか、認識エンジンに、未完了の非同期認識操作が存在しています。

inputTextnullです。

inputText が空の文字列 ("") です。

compareOptionsIgnoreNonSpaceIgnoreSymbols、または StringSort フラグを含みます。

注釈

音声認識エンジンは、認識操作が SpeechDetectedエミュレートされていないかのように、、 SpeechHypothesizedSpeechRecognitionRejected、および SpeechRecognized イベントを発生させます。 認識エンジンは、非同期認識操作を完了すると、 イベントを EmulateRecognizeCompleted 発生させます。

認識エンジンは、入力フレーズに文法規則を適用するときに使用 compareOptions します。 Vista および Windows 7 に付属する認識エンジンは、 または IgnoreCase 値が存在する場合、大文字と小文字をOrdinalIgnoreCase区別します。 認識エンジンは常に文字幅を無視し、かな型は無視しません。 認識エンジンは、新しい行と余分な空白も無視し、句読点をリテラル入力として扱います。 文字幅とかな型の詳細については、 列挙を CompareOptions 参照してください。

このメソッドは、メソッドの同期例外がスローできる非使用例外をすべて返すタスクに格納します。 返されたタスクに例外が格納されている場合、その例外はタスクが待機されたときにスローされます。 などの ArgumentException使用例外は、引き続き同期的にスローされます。 格納されている例外については、 によって EmulateRecognize(String, CompareOptions)スローされる例外に関するページを参照してください。

こちらもご覧ください

適用対象