RecognitionResult.GetAudioForWordRange 메서드

정의

인식 결과에서 특정 단어 범위와 연결된 오디오 섹션을 가져옵니다.

public:
 System::Speech::Recognition::RecognizedAudio ^ GetAudioForWordRange(System::Speech::Recognition::RecognizedWordUnit ^ firstWord, System::Speech::Recognition::RecognizedWordUnit ^ lastWord);
public System.Speech.Recognition.RecognizedAudio GetAudioForWordRange (System.Speech.Recognition.RecognizedWordUnit firstWord, System.Speech.Recognition.RecognizedWordUnit lastWord);
member this.GetAudioForWordRange : System.Speech.Recognition.RecognizedWordUnit * System.Speech.Recognition.RecognizedWordUnit -> System.Speech.Recognition.RecognizedAudio
Public Function GetAudioForWordRange (firstWord As RecognizedWordUnit, lastWord As RecognizedWordUnit) As RecognizedAudio

매개 변수

firstWord
RecognizedWordUnit

범위 내에서 첫 번째 단어입니다.

lastWord
RecognizedWordUnit

범위 내에서 마지막 단어입니다.

반환

RecognizedAudio

단어 범위와 관련된 오디오 섹션입니다.

예외

SpeechRecognizer 또는 SpeechRecognitionEngine 개체의 EmulateRecognize 또는 EmulateRecognizeAsync 메서드에 대한 호출 결과 생성된 인식기

예제

다음 예제에서는 이름 입력을 허용 하는 문법에 대해서 만들고에 대 한 처리기를 연결 합니다 SpeechRecognized 이벤트입니다. 문법 구의 name 요소에 대 한 와일드 카드를 사용 합니다. 이벤트 처리기는 와일드 카드에서 오디오를 사용 하 여 만들고 인사말 프롬프트를 재생 합니다.

private Grammar CreateNameInputGrammar()  
{  
  GrammarBuilder wildcardBuilder = new GrammarBuilder();  
  wildcardBuilder.AppendWildcard();  
  SemanticResultKey nameKey =  
    new SemanticResultKey("Name", wildcardBuilder);  

  GrammarBuilder nameBuilder =  
    new GrammarBuilder("My name is");  
  nameBuilder.Append(nameKey);  

  Grammar nameGrammar = new Grammar(nameBuilder);  
  nameGrammar.Name = "Name input";  

  nameGrammar.SpeechRecognized +=  
    new EventHandler<SpeechRecognizedEventArgs>(  
      NameInputHandler);  

  return nameGrammar;  
}  

// Handle the SpeechRecognized event for the name grammar.  
private void NameInputHandler(object sender, SpeechRecognizedEventArgs e)  
{  
  if (e.Result == null) return;  

  RecognitionResult result = e.Result;  
  SemanticValue semantics = e.Result.Semantics;  

  if (semantics.ContainsKey("Name"))  
  {  
    RecognizedAudio nameAudio =  
      result.GetAudioForWordRange(  
        result.Words[3], result.Words[result.Words.Count - 1]);  

    // Save the audio. Create a directory and file as necessary.  
    FileInfo fi = new FileInfo(@"C:\temp\temp.wav");  
    if (!fi.Directory.Exists)  
    {  
      fi.Directory.Create();  
    }  
    FileStream stream = new FileStream(fi.FullName, FileMode.Create);  
    nameAudio.WriteToWaveStream(stream);  
    stream.Close();  

    // Greet the person using the saved audio.  
    SpeechSynthesizer synthesizer = new SpeechSynthesizer();  
    PromptBuilder builder = new PromptBuilder();  
    builder.AppendText("Hello");  
    builder.AppendAudio(fi.FullName);  
    synthesizer.Speak(builder);  
  }  
}  

설명

전체 오디오를 인식 결과와 연결을 사용 합니다 Audio 속성입니다.

적용 대상

추가 정보