다음을 통해 공유


SpeechSynthesizer.GetInstalledVoices Method

Definition

Returns the collection of speech synthesis (text-to-speech) voices that are currently installed on the system.

Overloads

GetInstalledVoices()

Returns all of the installed speech synthesis (text-to-speech) voices.

GetInstalledVoices(CultureInfo)

Returns all of the installed speech synthesis (text-to-speech) voices that support a specific locale.

Remarks

When an application calls GetInstalledVoices, the method verifies that each of the voices (engines for text-to-speech) it finds in the registry meets certain minimum criteria. For any voice that fails verification, GetInstalledVoices sets its Enabled property to False. An application cannot select a voice whose Enabled property is False. Typically, applications will not set a voice's Enabled property.

GetInstalledVoices()

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

Returns all of the installed speech synthesis (text-to-speech) voices.

public:
 System::Collections::ObjectModel::ReadOnlyCollection<System::Speech::Synthesis::InstalledVoice ^> ^ GetInstalledVoices();
public System.Collections.ObjectModel.ReadOnlyCollection<System.Speech.Synthesis.InstalledVoice> GetInstalledVoices ();
member this.GetInstalledVoices : unit -> System.Collections.ObjectModel.ReadOnlyCollection<System.Speech.Synthesis.InstalledVoice>
Public Function GetInstalledVoices () As ReadOnlyCollection(Of InstalledVoice)

Returns

Returns a read-only collection of the voices currently installed on the system.

Examples

The following example is part of a console application that initializes a SpeechSynthesizer object and outputs to the console a list of the installed voices (engines for speech synthesis) and demonstrates the information that is available for each voice.

using System;
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())
      {

        // Output information about all of the installed voices.
        Console.WriteLine("Installed voices -");
        foreach (InstalledVoice voice in synth.GetInstalledVoices())
        {
          VoiceInfo info = voice.VoiceInfo;
          string AudioFormats = "";
          foreach (SpeechAudioFormatInfo fmt in info.SupportedAudioFormats)
          {
            AudioFormats += String.Format("{0}\n",
            fmt.EncodingFormat.ToString());
          }

          Console.WriteLine(" Name:          " + info.Name);
          Console.WriteLine(" Culture:       " + info.Culture);
          Console.WriteLine(" Age:           " + info.Age);
          Console.WriteLine(" Gender:        " + info.Gender);
          Console.WriteLine(" Description:   " + info.Description);
          Console.WriteLine(" ID:            " + info.Id);
          Console.WriteLine(" Enabled:       " + voice.Enabled);
          if (info.SupportedAudioFormats.Count != 0)
          {
            Console.WriteLine( " Audio formats: " + AudioFormats);
          }
          else
          {
            Console.WriteLine(" No supported audio formats found");
          }

          string AdditionalInfo = "";
          foreach (string key in info.AdditionalInfo.Keys)
          {
            AdditionalInfo += String.Format("  {0}: {1}\n", key, info.AdditionalInfo[key]);
          }

          Console.WriteLine(" Additional Info - " + AdditionalInfo);
          Console.WriteLine();
        }
      }
      Console.WriteLine("Press any key to exit...");
      Console.ReadKey();
    }
  }
}

Remarks

A voice is an engine for speech synthesis (text-to-speech or TTS) that is installed on the system.

See also

Applies to

GetInstalledVoices(CultureInfo)

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

Returns all of the installed speech synthesis (text-to-speech) voices that support a specific locale.

public:
 System::Collections::ObjectModel::ReadOnlyCollection<System::Speech::Synthesis::InstalledVoice ^> ^ GetInstalledVoices(System::Globalization::CultureInfo ^ culture);
public System.Collections.ObjectModel.ReadOnlyCollection<System.Speech.Synthesis.InstalledVoice> GetInstalledVoices (System.Globalization.CultureInfo culture);
member this.GetInstalledVoices : System.Globalization.CultureInfo -> System.Collections.ObjectModel.ReadOnlyCollection<System.Speech.Synthesis.InstalledVoice>
Public Function GetInstalledVoices (culture As CultureInfo) As ReadOnlyCollection(Of InstalledVoice)

Parameters

culture
CultureInfo

The locale that the voice must support.

Returns

Returns a read-only collection of the voices currently installed on the system that support the specified locale.

Examples

The following example is part of a console application that initializes a SpeechSynthesizer object and outputs to the console a list of the installed voices that support the en-US locale.

using System;
using System.Globalization;
using System.Speech.Synthesis;

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

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

        // Output information about all of the installed voices that
        // support the en-US locale.
        Console.WriteLine("Installed voices for the en-US locale:");
        foreach (InstalledVoice voice in
          synthesizer.GetInstalledVoices(new CultureInfo("en-US")))
        {
          VoiceInfo info = voice.VoiceInfo;
          OutputVoiceInfo(info);
        }

        // Output information about the current voice.
        Console.WriteLine();
        Console.WriteLine("Current voice:");
        OutputVoiceInfo(synthesizer.Voice);
      }

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

    // Display information about a synthesizer voice.
    private static void OutputVoiceInfo(VoiceInfo info)
    {
      Console.WriteLine("  Name: {0}, culture: {1}, gender: {2}, age: {3}.",
        info.Name, info.Culture, info.Gender, info.Age);
      Console.WriteLine("    Description: {0}", info.Description);
    }
  }
}

Remarks

If none of the installed voices support the specified locale, this method returns an empty collection.

Microsoft Windows and the System.Speech API accept all valid language-country codes. To perform text-to-speech using the language specified in the Culture property, a speech synthesis engine that supports that language-country code must be installed. The speech synthesis engines that shipped with Microsoft Windows 7 work with the following language-country codes:

  • en-US. English (United States)

  • zh-CN. Chinese (China)

  • zh-TW. Chinese (Taiwan)

Two-letter language codes such as "en" are also permitted.

See also

Applies to