SetOutputToWaveStream Method

Microsoft Speech Platform SDK 11

Collapse imageExpand ImageCopy imageCopyHover image

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

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

Syntax

Visual Basic (Declaration)
Public Sub SetOutputToWaveStream ( _
	audioDestination As Stream _
)
Visual Basic (Usage)
Dim instance As SpeechSynthesizer
Dim audioDestination As Stream

instance.SetOutputToWaveStream(audioDestination)
C#
public void SetOutputToWaveStream(
	Stream audioDestination
)

Parameters

audioDestination
Type: System.IO..::..Stream

The stream to which to append synthesis output.

Remarks

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.

Examples

The following example outputs a phrase to a WAV stream.

 Copy imageCopy Code
using System;
using System.IO;
using Microsoft.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.
        synth.SetOutputToWaveStream(streamAudio);

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

        // Set the synthesizer output to null to release the stream. 
        synth.SetOutputToNull();

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

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

See Also