RecognitionResult.Audio 属性

定义

获取与识别结果关联的音频。

public:
 property System::Speech::Recognition::RecognizedAudio ^ Audio { System::Speech::Recognition::RecognizedAudio ^ get(); };
public System.Speech.Recognition.RecognizedAudio Audio { get; }
member this.Audio : System.Speech.Recognition.RecognizedAudio
Public ReadOnly Property Audio As RecognizedAudio

属性值

RecognizedAudio

如果识别器从启动调用的结果 SpeechRecognitionEngineSpeechRecognizer 实例的 nullEmulateRecognize 方法,音频与标识结果或 EmulateRecognizeAsync

示例

下面的示例演示了 SpeechRecognized 事件的处理程序以及有关关联的的某些信息 RecognitionResult

// Handle the SpeechRecognized event.   
void SpeechRecognizedHandler(object sender, SpeechRecognizedEventArgs e)  
{  
  if (e.Result == null) return;  

  // Add event handler code here.  

  // The following code illustrates some of the information available  
  // in the recognition result.  
      Console.WriteLine("Grammar({0}): {1}", e.Result.Grammar.Name, e.Result.Text);  
      Console.WriteLine("Audio for result:");  
      Console.WriteLine("  Start time: "+ e.Result.Audio.StartTime);  
      Console.WriteLine("  Duration: " + e.Result.Audio.Duration);  
      Console.WriteLine("  Format: " + e.Result.Audio.Format.EncodingFormat);  

  // Display the semantic values in the recognition result.  
  foreach (KeyValuePair<String, SemanticValue> child in e.Result.Semantics)  
  {  
    Console.WriteLine(" {0} key: {1}",  
      child.Key, child.Value.Value ?? "null");  
  }  
  Console.WriteLine();  

  // Display information about the words in the recognition result.  
  foreach (RecognizedWordUnit word in e.Result.Words)  
  {  
    RecognizedAudio audio = e.Result.GetAudioForWordRange(word, word);  
    Console.WriteLine(" {0,-10} {1,-10} {2,-10} {3} ({4})",  
      word.Text, word.LexicalForm, word.Pronunciation,  
      audio.Duration, word.DisplayAttributes);  
  }  

  // Display the recognition alternates for the result.  
  foreach (RecognizedPhrase phrase in e.Result.Alternates)  
  {  
    Console.WriteLine(" alt({0}) {1}", phrase.Confidence, phrase.Text);  
  }  
}  

注解

若要获取与识别结果中的特定单词范围相关联的音频部分,请使用 GetAudioForWordRange 方法。

适用于

另请参阅