SpeechSynthesizer.SetOutputToWaveFile 方法

定義

設定SpeechSynthesizer物件,以便將輸出附加至波形音訊格式的檔案。

多載

SetOutputToWaveFile(String, SpeechAudioFormatInfo)

設定SpeechSynthesizer物件,以便將輸出附加至指定格式的波形音訊格式檔案。

SetOutputToWaveFile(String)

設定SpeechSynthesizer物件,以便將輸出附加至包含波形格式音訊的檔案。

備註

若要釋放 SpeechSynthesizer 檔案的參考, SpeechSynthesizer 請呼叫 SetOutputToNull 重新設定 的輸出,例如呼叫 。

如需其他輸出組態選項,請參閱 SetOutputToAudioStreamSetOutputToDefaultAudioDeviceSetOutputToNullSetOutputToWaveStream 方法。

SetOutputToWaveFile(String, SpeechAudioFormatInfo)

來源:
SpeechSynthesizer.cs
來源:
SpeechSynthesizer.cs
來源:
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)

來源:
SpeechSynthesizer.cs
來源:
SpeechSynthesizer.cs
來源:
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 方法。

另請參閱

適用於