SpeechRecognitionEngine.SetInputToAudioStream(Stream, SpeechAudioFormatInfo) SpeechRecognitionEngine.SetInputToAudioStream(Stream, SpeechAudioFormatInfo) SpeechRecognitionEngine.SetInputToAudioStream(Stream, SpeechAudioFormatInfo) SpeechRecognitionEngine.SetInputToAudioStream(Stream, SpeechAudioFormatInfo) Method

定義

SpeechRecognitionEngine オブジェクトを、オーディオ ストリームからの入力を受け取るように構成します。Configures the SpeechRecognitionEngine object to receive input from an audio stream.

public:
 void SetInputToAudioStream(System::IO::Stream ^ audioSource, System::Speech::AudioFormat::SpeechAudioFormatInfo ^ audioFormat);
public void SetInputToAudioStream (System.IO.Stream audioSource, System.Speech.AudioFormat.SpeechAudioFormatInfo audioFormat);
member this.SetInputToAudioStream : System.IO.Stream * System.Speech.AudioFormat.SpeechAudioFormatInfo -> unit
Public Sub SetInputToAudioStream (audioSource As Stream, audioFormat As SpeechAudioFormatInfo)

パラメーター

audioSource
Stream Stream Stream Stream

オーディオ入力ストリーム。The audio input stream.

audioFormat
SpeechAudioFormatInfo SpeechAudioFormatInfo SpeechAudioFormatInfo SpeechAudioFormatInfo

オーディオ入力の形式。The format of the audio input.

次の例では、基本的な音声認識を示すコンソール アプリケーションの一部を示します。The following example shows part of a console application that demonstrates basic speech recognition. 例では、オーディオ ファイルのフレーズを含む、example.wav から入力を使用して"1 つのテストをテストする 2 つ 3"および"先々 cooper"、一時停止で区切られました。The example uses input from an audio file, example.wav, that contains the phrases, "testing testing one two three" and "mister cooper", separated by a pause. 例では、次の出力を生成します。The example generates the following output.


Starting asynchronous recognition...  
  Recognized text =  Testing testing 123  
  Recognized text =  Mr. Cooper  
  End of stream encountered.  
Done.  

Press any key to exit...  

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

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

    static void Main(string[] args)  
    {  
      using (SpeechRecognitionEngine recognizer =  
        new SpeechRecognitionEngine(new CultureInfo("en-US")))  
      {  

        // Create and load a grammar.  
        Grammar dictation = new DictationGrammar();  
        dictation.Name = "Dictation Grammar";  

        recognizer.LoadGrammar(dictation);  

        // Configure the input to the recognizer.  
        recognizer.SetInputToAudioStream(  
          File.OpenRead(@"c:\temp\audioinput\example.wav"),  
          new SpeechAudioFormatInfo(  
            44100, AudioBitsPerSample.Sixteen, AudioChannel.Mono));  

        // Attach event handlers.  
        recognizer.SpeechRecognized +=  
          new EventHandler<SpeechRecognizedEventArgs>(  
            SpeechRecognizedHandler);  
        recognizer.RecognizeCompleted +=  
          new EventHandler<RecognizeCompletedEventArgs>(  
            RecognizeCompletedHandler);  

        // Perform recognition of the whole file.  
        Console.WriteLine("Starting asynchronous recognition...");  
        completed = false;  
        recognizer.RecognizeAsync(RecognizeMode.Multiple);  

        while (!completed)  
        {  
          Thread.Sleep(333);  
        }  
        Console.WriteLine("Done.");  
      }  

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

    // Handle the SpeechRecognized event.  
    static void SpeechRecognizedHandler(  
      object sender, SpeechRecognizedEventArgs e)  
    {  
      if (e.Result != null && e.Result.Text != null)  
      {  
        Console.WriteLine("  Recognized text =  {0}", e.Result.Text);  
      }  
      else  
      {  
        Console.WriteLine("  Recognized text not available.");  
      }  
    }  

    // Handle the RecognizeCompleted event.  
    static void RecognizeCompletedHandler(  
      object sender, RecognizeCompletedEventArgs e)  
    {  
      if (e.Error != null)  
      {  
        Console.WriteLine("  Error encountered, {0}: {1}",  
          e.Error.GetType().Name, e.Error.Message);  
      }  
      if (e.Cancelled)  
      {  
        Console.WriteLine("  Operation cancelled.");  
      }  
      if (e.InputStreamEnded)  
      {  
        Console.WriteLine("  End of stream encountered.");  
      }  

      completed = true;  
    }  
  }  
}  

注釈

認識エンジンでは、認識操作中に、入力ストリームの末尾に達すると、使用可能な入力の認識操作を終了します。If the recognizer reaches the end of the input stream during a recognition operation, the recognition operation finalizes with the available input. 後続の認識操作は、認識エンジンに対する入力を更新する場合を除き、例外を生成できます。Any subsequent recognition operations can generate an exception, unless you update the input to the recognizer.

適用対象

こちらもご覧ください