SpeechSynthesizer.SetOutputToWaveFile Método

Definición

Configura el objeto SpeechSynthesizer para anexar la salida a un archivo con formato de audio de forma de onda.

Sobrecargas

SetOutputToWaveFile(String, SpeechAudioFormatInfo)

Configura el objeto SpeechSynthesizer para anexar la salida a un archivo de formato de audio de forma de onda en un formato especificado.

SetOutputToWaveFile(String)

Configura el objeto SpeechSynthesizer para anexar la salida a un archivo que contiene audio de formato de forma de onda.

Comentarios

Para liberar la SpeechSynthesizerreferencia del archivo, vuelva a configurar la SpeechSynthesizersalida de , por ejemplo, llamando a SetOutputToNull.

Para ver otras opciones de configuración de salida, vea los SetOutputToAudioStreammétodos , SetOutputToDefaultAudioDevice, SetOutputToNully SetOutputToWaveStream .

SetOutputToWaveFile(String, SpeechAudioFormatInfo)

Source:
SpeechSynthesizer.cs
Source:
SpeechSynthesizer.cs

Configura el objeto SpeechSynthesizer para anexar la salida a un archivo de formato de audio de forma de onda en un formato especificado.

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)

Parámetros

path
String

Ruta de acceso al archivo.

formatInfo
SpeechAudioFormatInfo

Información de formato de audio.

Ejemplos

En el ejemplo siguiente se especifica el formato de la salida de síntesis de voz y se envía a un archivo WAV.

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();
    }
  }
}

Consulte también

Se aplica a

SetOutputToWaveFile(String)

Source:
SpeechSynthesizer.cs
Source:
SpeechSynthesizer.cs

Configura el objeto SpeechSynthesizer para anexar la salida a un archivo que contiene audio de formato de forma de onda.

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

Parámetros

path
String

Ruta de acceso al archivo.

Ejemplos

En el ejemplo siguiente se usa una instancia de SoundPlayer para reproducir un símbolo del sistema que se ha generado en un archivo .wav. Dado que la SpeakAsync llamada es asincrónica, la SoundPlayer instancia se crea (y el Play método invocado) en el controlador del SpeakCompleted evento.

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();
    }
  }
}

Comentarios

Para configurar la salida y especificar el formato de audio, use el SetOutputToWaveFile método .

Consulte también

Se aplica a