SpeechSynthesizer.SetOutputToWaveStream Method (Stream)


Configures the SpeechSynthesizer object to append output to a stream that contains Waveform format audio.

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

public void SetOutputToWaveStream(
	Stream audioDestination


Type: System.IO.Stream

The stream to which to append synthesis output.

To release the SpeechSynthesizer’s reference to the stream, reconfigure the synthesizer's output, for example, by calling SetOutputToNull.

For other output configuration options, see the SetOutputToAudioStream, SetOutputToDefaultAudioDevice, SetOutputToNull, and SetOutputToWaveFile methods.

The following example outputs a phrase to a WAV stream.

using System;
using System.IO;
using System.Speech.Synthesis;

namespace SampleSynthesis
  class Program
    static void Main(string[] args)

      // Initialize a new instance of the speech synthesizer.
      using (SpeechSynthesizer synth = new SpeechSynthesizer())
      using (MemoryStream stream = new MemoryStream())

        // Create a SoundPlayer instance to play the output audio file.
        MemoryStream streamAudio = new MemoryStream();
        System.Media.SoundPlayer m_SoundPlayer = new System.Media.SoundPlayer();

        // Configure the synthesizer to output to an audio stream.

        // Speak a phrase.
        synth.Speak("This is sample text-to-speech output.");
        streamAudio.Position = 0;
        m_SoundPlayer.Stream = streamAudio;

        // Set the synthesizer output to null to release the stream. 

        // Insert code to persist or process the stream contents here.

      Console.WriteLine("Press any key to exit...");

.NET Framework
Available since 3.0
Return to top