RecognitionResult.Audio Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets the audio associated with the recognition result.
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
Property Value
The audio associated with the recognition result or null
if the recognizer generated the result from a call to the EmulateRecognize
or EmulateRecognizeAsync
methods of a SpeechRecognitionEngine or SpeechRecognizer instance.
Examples
The following example shows a handler for the SpeechRecognized event and some of the information about the associated 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);
}
}
Remarks
To get a section of the audio that is associated with a specific range of words in the recognition result, use the GetAudioForWordRange method.