SpeechRecognitionEngine.EmulateRecognize メソッド

定義

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

オーバーロード

EmulateRecognize(String)

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

EmulateRecognize(RecognizedWordUnit[], CompareOptions)

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

EmulateRecognize(String, CompareOptions)

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

注釈

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

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

Note

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

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

EmulateRecognize(String)

Source:
SpeechRecognitionEngine.cs
Source:
SpeechRecognitionEngine.cs

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

public:
 System::Speech::Recognition::RecognitionResult ^ EmulateRecognize(System::String ^ inputText);
public System.Speech.Recognition.RecognitionResult EmulateRecognize (string inputText);
member this.EmulateRecognize : string -> System.Speech.Recognition.RecognitionResult
Public Function EmulateRecognize (inputText As String) As RecognitionResult

パラメーター

inputText
String

認識操作の入力。

戻り値

認識操作の結果。操作が不適切だったり、認識エンジンが有効でない場合は null

例外

認識エンジンに読み込まれている音声認識文法がありません。

inputTextnullです。

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

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

TestRecognize("Smith")...  
 SpeechDetected event raised.  
 SpeechRecognized event raised.  
  Grammar = Smith; Text = Smith  
...Recognition result text = Smith  

TestRecognize("Jones")...  
 SpeechDetected event raised.  
 SpeechRecognized event raised.  
  Grammar = Jones; Text = Jones  
...Recognition result text = Jones  

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

TestRecognize("Mister Smith")...  
 SpeechDetected event raised.  
 SpeechRecognized event raised.  
  Grammar = Smith; Text = mister Smith  
...Recognition result text = mister Smith  

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

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

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

        // Load grammars.  
        recognizer.LoadGrammar(CreateNameGrammar("Smith"));  
        recognizer.LoadGrammar(CreateNameGrammar("Jones"));  

        // Disable audio input to the recognizer.  
        recognizer.SetInputToNull();  

        // Add handlers for events raised by the EmulateRecognize 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);  

        // Start four synchronous emulated recognition operations.  
        TestRecognize(recognizer, "Smith");  
        TestRecognize(recognizer, "Jones");  
        TestRecognize(recognizer, "Mister");  
        TestRecognize(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 synchronous recognition.  
    private static void TestRecognize(  
      SpeechRecognitionEngine recognizer, string input)  
    {  
      Console.WriteLine("TestRecognize(\"{0}\")...", input);  
      RecognitionResult result =  
        recognizer.EmulateRecognize(input,CompareOptions.IgnoreCase);  
      if (result != null)  
      {  
        Console.WriteLine("...Recognition result text = {0}",  
          result.Text ?? "<null>");  
      }  
      else  
      {  
        Console.WriteLine("...No recognition result.");  
      }  
      Console.WriteLine();  
    }  

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

    // Handle events.  
    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.");  
      }  
    }  

    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.");  
      }  
    }  
  }  
}  

注釈

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

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

こちらもご覧ください

適用対象

EmulateRecognize(RecognizedWordUnit[], CompareOptions)

Source:
SpeechRecognitionEngine.cs
Source:
SpeechRecognitionEngine.cs

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

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

パラメーター

wordUnits
RecognizedWordUnit[]

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

compareOptions
CompareOptions

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

戻り値

認識操作の結果。操作が不適切だったり、認識エンジンが有効でない場合は null

例外

認識エンジンに読み込まれている音声認識文法がありません。

wordUnitsnullです。

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

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

注釈

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

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

こちらもご覧ください

適用対象

EmulateRecognize(String, CompareOptions)

Source:
SpeechRecognitionEngine.cs
Source:
SpeechRecognitionEngine.cs

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

public:
 System::Speech::Recognition::RecognitionResult ^ EmulateRecognize(System::String ^ inputText, System::Globalization::CompareOptions compareOptions);
public System.Speech.Recognition.RecognitionResult EmulateRecognize (string inputText, System.Globalization.CompareOptions compareOptions);
member this.EmulateRecognize : string * System.Globalization.CompareOptions -> System.Speech.Recognition.RecognitionResult
Public Function EmulateRecognize (inputText As String, compareOptions As CompareOptions) As RecognitionResult

パラメーター

inputText
String

認識操作の入力語句。

compareOptions
CompareOptions

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

戻り値

認識操作の結果。操作が不適切だったり、認識エンジンが有効でない場合は null

例外

認識エンジンに読み込まれている音声認識文法がありません。

inputTextnullです。

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

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

注釈

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

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

こちらもご覧ください

適用対象