RecognizedAudio.GetRange(TimeSpan, TimeSpan) 메서드

정의

현재 인식된 오디오의 섹션을 이진 데이터로 선택하고 반환합니다.

public:
 System::Speech::Recognition::RecognizedAudio ^ GetRange(TimeSpan audioPosition, TimeSpan duration);
public System.Speech.Recognition.RecognizedAudio GetRange(TimeSpan audioPosition, TimeSpan duration);
member this.GetRange : TimeSpan * TimeSpan -> System.Speech.Recognition.RecognizedAudio
Public Function GetRange (audioPosition As TimeSpan, duration As TimeSpan) As RecognizedAudio

매개 변수

audioPosition
TimeSpan

반환할 오디오 데이터의 시작점입니다.

duration
TimeSpan

반환할 세그먼트의 길이입니다.

반품

정의된 audioPosition 대로 인식된 오디오의 하위 섹션을 반환합니다 duration.

예외

audioPosition 현재 duration 세그먼트의 범위를 벗어나는 오디오 세그먼트를 정의합니다.

현재 인식된 오디오에는 데이터가 없습니다.

예제

다음 예제에서는 이름 입력에 대한 음성 인식 문법을 만들고, 이벤트에 대한 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);
  }
}

적용 대상

추가 정보