RecognizedAudio.WriteToWaveStream(Stream) 메서드

정의

오디오를 웨이브 형식으로 스트림에 씁니다.

public:
 void WriteToWaveStream(System::IO::Stream ^ outputStream);
public void WriteToWaveStream(System.IO.Stream outputStream);
member this.WriteToWaveStream : System.IO.Stream -> unit
Public Sub WriteToWaveStream (outputStream As Stream)

매개 변수

outputStream
Stream

오디오 데이터를 받을 스트림입니다.

예제

다음 예제에서는 이름 입력에 대한 음성 인식 문법을 만들고, 이벤트에 대한 SpeechRecognized 처리기를 추가하고, 문법을 In-Process 음성 인식기에 로드합니다. 그런 다음 입력의 이름 부분에 대한 오디오 정보를 오디오 파일에 씁니다. 오디오 파일은 녹음된 오디오를 SpeechSynthesizer 포함하는 구를 말하는 개체에 대한 입력으로 사용됩니다.

private static void AddNameGrammar(SpeechRecognitionEngine recognizer)
{
  GrammarBuilder builder = new GrammarBuilder();
  builder.Append("My name is");
  builder.AppendWildcard();

  Grammar nameGrammar = new Grammar(builder);
  nameGrammar.Name = "Name Grammar";
  nameGrammar.SpeechRecognized +=
    new EventHandler<SpeechRecognizedEventArgs>(
      NameSpeechRecognized);

  recognizer.LoadGrammar(nameGrammar);
}

// Handle the SpeechRecognized event of the name grammar.
private static void NameSpeechRecognized(
  object sender, SpeechRecognizedEventArgs e)
{
  Console.WriteLine("Grammar ({0}) recognized speech: {1}",
    e.Result.Grammar.Name, e.Result.Text);

  try
  {
    // The name phrase starts after the first three words.
    if (e.Result.Words.Count < 4)
    {

      // Add code to check for an alternate that contains the
wildcard.
      return;
    }

    RecognizedAudio audio = e.Result.Audio;
    TimeSpan start = e.Result.Words[3].AudioPosition;
    TimeSpan duration = audio.Duration - start;

    // Add code to verify and persist the audio.
    string path = @"C:\temp\nameAudio.wav";
    using (Stream outputStream = new FileStream(path, FileMode.Create))
    {
      RecognizedAudio nameAudio = audio.GetRange(start, duration);
      nameAudio.WriteToWaveStream(outputStream);
      outputStream.Close();
    }

    Thread testThread =
      new Thread(new ParameterizedThreadStart(TestAudio));
    testThread.Start(path);
  }
  catch (Exception ex)
  {
    Console.WriteLine("Exception thrown while processing audio:");
    Console.WriteLine(ex.ToString());
  }
}

// Use the speech synthesizer to play back the .wav file
// that was created in the SpeechRecognized event handler.

private static void TestAudio(object item)
{
  string path = item as string;
  if (path != null && File.Exists(path))
  {
    SpeechSynthesizer synthesizer = new SpeechSynthesizer();
    PromptBuilder builder = new PromptBuilder();
    builder.AppendText("Hello");
    builder.AppendAudio(path);
    synthesizer.Speak(builder);
  }
}

설명

오디오 데이터는 RIFF(리소스 교환 파일 형식) 헤더를 포함하는 Wave 형식으로 작성 outputStream 됩니다.

메서드는 WriteToAudioStream 동일한 이진 형식을 사용하지만 Wave 헤더는 포함하지 않습니다.

적용 대상

추가 정보