Share via


SpeechSynthesizer.SetOutputToWaveFile Metodo

Definizione

Configura l'oggetto SpeechSynthesizer per aggiungere l'output a un file in formato audio Waveform.

Overload

SetOutputToWaveFile(String, SpeechAudioFormatInfo)

Configura l'oggetto SpeechSynthesizer per aggiungere l'output a un file in formato audio Waveform in un formato specificato.

SetOutputToWaveFile(String)

Configura l'oggetto SpeechSynthesizer per aggiungere l'output a un file che contiene l'audio in formato Waveform.

Commenti

Per rilasciare il SpeechSynthesizerriferimento al file, riconfigurare l'output SpeechSynthesizer, ad esempio chiamando SetOutputToNull.

Per altre opzioni di configurazione di output, vedere i SetOutputToAudioStreammetodi , SetOutputToDefaultAudioDevice, SetOutputToNulle SetOutputToWaveStream .

SetOutputToWaveFile(String, SpeechAudioFormatInfo)

Origine:
SpeechSynthesizer.cs
Origine:
SpeechSynthesizer.cs
Origine:
SpeechSynthesizer.cs

Configura l'oggetto SpeechSynthesizer per aggiungere l'output a un file in formato audio Waveform in un formato specificato.

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)

Parametri

path
String

Percorso del file.

formatInfo
SpeechAudioFormatInfo

Informazioni sul formato audio.

Esempio

Nell'esempio seguente viene specificato il formato dell'output della sintesi vocale e lo invia a un file 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();
    }
  }
}

Vedi anche

Si applica a

SetOutputToWaveFile(String)

Origine:
SpeechSynthesizer.cs
Origine:
SpeechSynthesizer.cs
Origine:
SpeechSynthesizer.cs

Configura l'oggetto SpeechSynthesizer per aggiungere l'output a un file che contiene l'audio in formato Waveform.

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

Parametri

path
String

Percorso del file.

Esempio

Nell'esempio seguente viene usata un'istanza di SoundPlayer per riprodurre un prompt che è stato restituito a un file con estensione wav. Poiché la chiamata è asincrona, l'istanza SpeakAsyncSoundPlayer viene creata (e il Play metodo richiamato) nel gestore per l'evento SpeakCompleted .

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

Commenti

Per configurare l'output e specificare il formato audio, usare il SetOutputToWaveFile metodo .

Vedi anche

Si applica a