SpeechSynthesizer.SetOutputToWaveFile 方法

定义

配置 SpeechSynthesizer 对象以追加输出到波形音频格式文件。

重载

SetOutputToWaveFile(String, SpeechAudioFormatInfo)

配置 SpeechSynthesizer 对象以追加输出到指定格式中的波形音频格式文件。

SetOutputToWaveFile(String)

配置 SpeechSynthesizer 对象以追加输出到包含波形格式音频的文件。

注解

若要释放 对 SpeechSynthesizer文件的引用,请重新配置 SpeechSynthesizer的输出,例如,通过调用 SetOutputToNull

有关其他输出配置选项,请参阅 SetOutputToAudioStreamSetOutputToDefaultAudioDeviceSetOutputToNullSetOutputToWaveStream 方法。

SetOutputToWaveFile(String, SpeechAudioFormatInfo)

Source:
SpeechSynthesizer.cs
Source:
SpeechSynthesizer.cs
Source:
SpeechSynthesizer.cs

配置 SpeechSynthesizer 对象以追加输出到指定格式中的波形音频格式文件。

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)

参数

path
String

文件的路径。

formatInfo
SpeechAudioFormatInfo

音频格式信息。

示例

以下示例指定语音合成输出的格式,并将其发送到 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();
    }
  }
}

另请参阅

适用于

SetOutputToWaveFile(String)

Source:
SpeechSynthesizer.cs
Source:
SpeechSynthesizer.cs
Source:
SpeechSynthesizer.cs

配置 SpeechSynthesizer 对象以追加输出到包含波形格式音频的文件。

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

参数

path
String

文件的路径。

示例

以下示例使用 的 SoundPlayer 实例播放已输出到 .wav 文件的提示。 SpeakAsync由于调用是异步的,因此 (SoundPlayer创建实例,Play并在事件的处理程序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();
    }
  }
}

注解

若要配置输出并指定音频格式,请使用 SetOutputToWaveFile 方法。

另请参阅

适用于