SpeechSynthesizer.SetOutputToWaveFile Methode

Definition

Konfiguriert das Objekt, um die SpeechSynthesizer Ausgabe an eine Waveform-Audioformatdatei anzufügen.

Überlädt

Name Beschreibung
SetOutputToWaveFile(String, SpeechAudioFormatInfo)

Konfiguriert das Objekt, um die SpeechSynthesizer Ausgabe an eine Waveform-Audioformatdatei in einem angegebenen Format anzufügen.

SetOutputToWaveFile(String)

Konfiguriert das Objekt, um die SpeechSynthesizer Ausgabe an eine Datei anzufügen, die Audiodaten im Waveform-Format enthält.

Hinweise

Um den SpeechSynthesizerVerweis auf die Datei freizugeben, konfigurieren Sie die SpeechSynthesizerAusgabe neu, z. B. durch Aufrufen SetOutputToNull.

Weitere Ausgabekonfigurationsoptionen finden Sie unter den SetOutputToAudioStreamMethoden , , SetOutputToDefaultAudioDevice, SetOutputToNullund SetOutputToWaveStream

SetOutputToWaveFile(String, SpeechAudioFormatInfo)

Konfiguriert das Objekt, um die SpeechSynthesizer Ausgabe an eine Waveform-Audioformatdatei in einem angegebenen Format anzufügen.

public:
 void SetOutputToWaveFile(System::String ^ path, System::Speech::AudioFormat::SpeechAudioFormatInfo ^ formatInfo);
public void SetOutputToWaveFile(string path, System.Speech.AudioFormat.SpeechAudioFormatInfo formatInfo);
member this.SetOutputToWaveFile : string * System.Speech.AudioFormat.SpeechAudioFormatInfo -> unit
Public Sub SetOutputToWaveFile (path As String, formatInfo As SpeechAudioFormatInfo)

Parameter

path
String

Der Pfad zur Datei.

formatInfo
SpeechAudioFormatInfo

Die Audioformatinformationen.

Beispiele

Im folgenden Beispiel wird das Format der Ausgabe der Sprachsynthese angegeben und an eine WAV-Datei gesendet.

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

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

      // Initialize a new instance of the SpeechSynthesizer.
      using (SpeechSynthesizer synth = new SpeechSynthesizer())
      {

        // Configure the audio output.
        synth.SetOutputToWaveFile(@"C:\temp\test.wav",
          new SpeechAudioFormatInfo(32000, AudioBitsPerSample.Sixteen, AudioChannel.Mono));

        // Create a SoundPlayer instance to play output audio file.
        System.Media.SoundPlayer m_SoundPlayer =
          new System.Media.SoundPlayer(@"C:\temp\test.wav");

        // Build a prompt.
        PromptBuilder builder = new PromptBuilder();
        builder.AppendText("This is sample output to a WAVE file.");

        // Speak the prompt.
        synth.Speak(builder);
        m_SoundPlayer.Play();
      }

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

Weitere Informationen

Gilt für:

SetOutputToWaveFile(String)

Konfiguriert das Objekt, um die SpeechSynthesizer Ausgabe an eine Datei anzufügen, die Audiodaten im Waveform-Format enthält.

public:
 void SetOutputToWaveFile(System::String ^ path);
public void SetOutputToWaveFile(string path);
member this.SetOutputToWaveFile : string -> unit
Public Sub SetOutputToWaveFile (path As String)

Parameter

path
String

Der Pfad zur Datei.

Beispiele

Im folgenden Beispiel wird eine Instanz verwendet, um SoundPlayer eine Eingabeaufforderung wiederzugeben, die in eine .wav Datei ausgegeben wurde. Da der SpeakAsync Aufruf asynchron ist, wird die SoundPlayer Instanz (und die Play methode aufgerufen) im Handler für das SpeakCompleted Ereignis erstellt.

using System;
using System.Speech.Synthesis;

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

      // Initialize a new instance of the SpeechSynthesizer.
      SpeechSynthesizer synth = new SpeechSynthesizer();

      // Configure the audio output.
      synth.SetOutputToWaveFile(@"C:\Test\Sample.wav");

      // Register for the SpeakCompleted event.
      synth.SpeakCompleted += new EventHandler<SpeakCompletedEventArgs>(synth_SpeakCompleted);

      // Build a prompt.
      PromptBuilder builder = new PromptBuilder();
      builder.AppendText("This sample asynchronously speaks a prompt to a WAVE file.");

      // Speak the string asynchronously.
      synth.SpeakAsync(builder);

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

    // Handle the SpeakCompleted event.
    static void synth_SpeakCompleted(object sender, SpeakCompletedEventArgs e)
    {

      // Create a SoundPlayer instance to play the output audio file.
      System.Media.SoundPlayer m_SoundPlayer =
        new System.Media.SoundPlayer(@"C:\Test\Sample.wav");

      //  Play the output file.
      m_SoundPlayer.Play();
    }
  }
}

Hinweise

Verwenden Sie die SetOutputToWaveFile Methode, um die Ausgabe zu konfigurieren und das Audioformat anzugeben.

Weitere Informationen

Gilt für: