SpeechSynthesizer.SetOutputToDefaultAudioDevice Method

Definition

Configures the SpeechSynthesizer object to send output to the default audio device.

C#
public void SetOutputToDefaultAudioDevice();

Examples

The following example uses the synthesizer to speak a phrase to the default audio output.

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

Remarks

You can use the Sound window in the Windows Control Panel to configure the default audio device for the computer.

For other output configuration options, see the SetOutputToAudioStream, SetOutputToNull, SetOutputToWaveFile, and SetOutputToWaveStream methods.

Applies to

Proizvod Verzije
.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)