SpeechSynthesizer.SetOutputToDefaultAudioDevice 方法

定義

設定SpeechSynthesizer物件,以便將輸出傳送至預設音訊裝置。

public:
 void SetOutputToDefaultAudioDevice();
public void SetOutputToDefaultAudioDevice ();
member this.SetOutputToDefaultAudioDevice : unit -> unit
Public Sub SetOutputToDefaultAudioDevice ()

範例

下列範例會使用合成器將片語讀出預設音訊輸出。

using System;
using System.Speech.Synthesis;

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

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

        // Configure the synthesizer to send output to the default audio device.
        synth.SetOutputToDefaultAudioDevice();

        // Speak a phrase.
        synth.Speak("This is sample text-to-speech output.");
      }

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

備註

您可以使用 Windows主控台中的[音效] 視窗來設定電腦的預設音訊裝置。

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

適用於