Language

SpeechRecognitionEngine.EmulateRecognize メソッド

定義

同期音声認識のためにオーディオの代わりにテキストを使用して、音声認識エンジンへの入力をエミュレートします。

オーバーロード

名前 説明
EmulateRecognize(String)

同期音声認識のためにオーディオの代わりにテキストを使用して、音声認識エンジンへの語句の入力をエミュレートします。

EmulateRecognize(RecognizedWordUnit[], CompareOptions)

同期音声認識のためにオーディオの代わりにテキストを使用して、音声認識エンジンに対する特定の単語の入力をエミュレートし、認識エンジンが単語と読み込まれた音声認識文法の Unicode 比較を処理する方法を指定します。

EmulateRecognize(String, CompareOptions)

同期音声認識のためにオーディオの代わりにテキストを使用して、音声認識エンジンへの語句の入力をエミュレートし、認識エンジンが語句と読み込まれた音声認識文法の間の Unicode 比較を処理する方法を指定します。

注釈

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

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

Note

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

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

EmulateRecognize(String)

ソース:
SpeechRecognitionEngine.cs
ソース:
SpeechRecognitionEngine.cs
ソース:
SpeechRecognitionEngine.cs
ソース:
SpeechRecognitionEngine.cs

同期音声認識のためにオーディオの代わりにテキストを使用して、音声認識エンジンへの語句の入力をエミュレートします。

public:
 System::Speech::Recognition::RecognitionResult ^ EmulateRecognize(System::String ^ inputText);
public System.Speech.Recognition.RecognitionResult? EmulateRecognize(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 。

例外

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

inputText は nullです。

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、 SpeechHypothesized、 SpeechRecognitionRejected、および SpeechRecognized イベントを発生させます。

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

こちらもご覧ください

適用対象

EmulateRecognize(RecognizedWordUnit[], CompareOptions)

ソース:
SpeechRecognitionEngine.cs
ソース:
SpeechRecognitionEngine.cs
ソース:
SpeechRecognitionEngine.cs
ソース:
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);
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 。

例外

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

wordUnits は nullです。

wordUnits には、1 つ以上の null 要素が含まれています。

compareOptions には、 IgnoreNonSpace、 IgnoreSymbols、または StringSort フラグが含まれています。

注釈

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

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

こちらもご覧ください

適用対象

EmulateRecognize(String, CompareOptions)

ソース:
SpeechRecognitionEngine.cs
ソース:
SpeechRecognitionEngine.cs
ソース:
SpeechRecognitionEngine.cs
ソース:
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);
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 。

例外

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

inputText は nullです。

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

compareOptions には、 IgnoreNonSpace、 IgnoreSymbols、または StringSort フラグが含まれています。

注釈

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

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

こちらもご覧ください

適用対象