SpeechRecognitionEngine.SetInputToAudioStream 메서드

정의

SpeechRecognitionEngine 오디오 스트림에서 입력을 받도록 개체를 구성합니다.

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

오디오 입력 스트림입니다.

audioFormat
SpeechAudioFormatInfo

오디오 입력의 형식입니다.

예제

다음 예제에서는 기본 음성 인식을 보여 주는 콘솔 애플리케이션의 일부를 보여 줍니다. 이 예제에서는 일시 중지로 구분된 "테스트 1개의 3개 테스트" 및 "미스터 쿠퍼"라는 문구가 포함된 오디오 파일 example.wav 입력을 사용합니다. 이 예제에서는 다음 출력을 생성합니다.

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;
    }
  }
}

설명

인식 작업 중에 인식기가 입력 스트림의 끝에 도달하면 인식 작업이 사용 가능한 입력으로 마무리됩니다. 인식기에서 입력을 업데이트하지 않는 한 후속 인식 작업은 예외를 생성할 수 있습니다.

적용 대상

추가 정보