SpeechSynthesizer.SetOutputToWaveStream(Stream) Metoda

Definicja

Konfiguruje SpeechSynthesizer obiekt do dołączania danych wyjściowych do strumienia zawierającego format Wave.

public:
 void SetOutputToWaveStream(System::IO::Stream ^ audioDestination);
public void SetOutputToWaveStream (System.IO.Stream audioDestination);
member this.SetOutputToWaveStream : System.IO.Stream -> unit
Public Sub SetOutputToWaveStream (audioDestination As Stream)

Parametry

audioDestination
Stream

Strumień, do którego mają zostać dołączone dane wyjściowe syntezy.

Przykłady

Poniższy przykład wyprowadza frazę do strumienia WAV.

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 streamAudio = new MemoryStream())  
      {  

        // Create a SoundPlayer instance to play the output audio file.  
        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("This is 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();  
    }  
  }  
}  

Uwagi

Aby zwolnić SpeechSynthesizer odwołanie do strumienia, ponownie skonfiguruj dane wyjściowe syntezatora, na przykład przez wywołanie metody SetOutputToNull .

Aby poznać inne opcje konfiguracji wyjściowej, SetOutputToAudioStream Zobacz SetOutputToDefaultAudioDevice metody,, SetOutputToNull , i SetOutputToWaveFile .

Dotyczy