This documentation is archived and is not being maintained.

RecognizedAudio Class

Represents audio input that is associated with a RecognitionResult.


Namespace:  System.Speech.Recognition
Assembly:  System.Speech (in System.Speech.dll)

public class RecognizedAudio

The RecognizedAudio type exposes the following members.

Public propertyAudioPositionGets the location in the input audio stream for the start of the recognized audio.
Public propertyDurationGets the duration of the input audio stream for the recognized audio.
Public propertyFormatGets the format of the audio processed by a recognition engine.
Public propertyStartTimeGets the system time at the start of the recognition operation.

Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetRangeSelects and returns a section of the current recognized audio as binary data.
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Public methodWriteToAudioStreamWrites the entire audio to a stream as raw data.
Public methodWriteToWaveStreamWrites audio to a stream in Wave format.

A speech recognizer generates information about the audio input as part of the recognition operation. To access the recognized audio, use the Audio property or the GetAudioForWordRange method of the RecognitionResult.

A recognition result can be produced by the following events and methods of the SpeechRecognizer and SpeechRecognitionEngine classes:

Important noteImportant

A recognition result produced by emulated speech recognition does not contain recognized audio. For such a recognition result, its Audio property returns null and its GetAudioForWordRange method throws an exception. For more information about emulated speech recognition, see the EmulateRecognize and EmulateRecognizeAsync methods of the SpeechRecognizer and SpeechRecognitionEngine classes.

The following example handles the SpeechRecognitionEngine.SpeechRecognized, SpeechRecognizer.SpeechRecognized, or Grammar.SpeechRecognized event and outputs to the console information about the recognized audio that is associated with the recognition result.

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

  RecognitionResult result = e.Result;
  Console.WriteLine("Grammar({0}): {1}",
    result.Grammar.Name, result.Text);

  if (e.Result.Audio != null)
    RecognizedAudio audio = e.Result.Audio;

    Console.WriteLine("   start time: {0}", audio.StartTime);
    Console.WriteLine("   encoding format: {0}", audio.Format.EncodingFormat);
    Console.WriteLine("   position: {0}, duration: {1}",
      audio.AudioPosition, audio.Duration);

  // Add event handler code here.

.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.