SpeechSynthesizer.SetOutputToDefaultAudioDevice 方法

定義

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

C#
public void SetOutputToDefaultAudioDevice();

範例

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

C#
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 方法。

適用於

產品 版本
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)