SpeechSynthesizer.GetInstalledVoices SpeechSynthesizer.GetInstalledVoices SpeechSynthesizer.GetInstalledVoices SpeechSynthesizer.GetInstalledVoices Method

定義

傳回目前已安裝在系統上的語音合成 (文字轉換語音) 語音集合。Returns the collection of speech synthesis (text-to-speech) voices that are currently installed on the system.

多載

GetInstalledVoices() GetInstalledVoices() GetInstalledVoices() GetInstalledVoices()

傳回所有已安裝的語音合成 (文字轉換語音) 語音。Returns all of the installed speech synthesis (text-to-speech) voices.

GetInstalledVoices(CultureInfo) GetInstalledVoices(CultureInfo) GetInstalledVoices(CultureInfo) GetInstalledVoices(CultureInfo)

傳回支援特定地區設定的所有已安裝語音合成 (文字轉換語音) 語音。Returns all of the installed speech synthesis (text-to-speech) voices that support a specific locale.

備註

當應用程式呼叫GetInstalledVoices時, 方法會驗證它在登錄中找到的每個語音 (文字轉換語音) 是否符合特定的最低準則。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. 針對驗證失敗的任何語音, GetInstalledVoices將其Enabled屬性設False為。For any voice that fails verification, GetInstalledVoices sets its Enabled property to False. 應用程式無法選取其Enabled屬性為False的聲音。An application cannot select a voice whose Enabled property is False. 通常, 應用程式不會設定語音的Enabled屬性。Typically, applications will not set a voice's Enabled property.

GetInstalledVoices() GetInstalledVoices() GetInstalledVoices() GetInstalledVoices()

傳回所有已安裝的語音合成 (文字轉換語音) 語音。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 a read-only collection of the voices currently installed on the system.

範例

下列範例是主控台應用程式的一部分, 它會初始化SpeechSynthesizer物件, 並將已安裝的語音 (適用于語音合成的引擎) 清單輸出到主控台, 並示範每個語音可用的資訊。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();  
    }  
  }  
}  
  

備註

語音是系統上所安裝之語音合成 (文字轉換語音或 TTS) 的引擎。A voice is an engine for speech synthesis (text-to-speech or TTS) that is installed on the system.

另請參閱

GetInstalledVoices(CultureInfo) GetInstalledVoices(CultureInfo) GetInstalledVoices(CultureInfo) GetInstalledVoices(CultureInfo)

傳回支援特定地區設定的所有已安裝語音合成 (文字轉換語音) 語音。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)

參數

culture
CultureInfo CultureInfo CultureInfo CultureInfo

語音必須支援的地區設定。The locale that the voice must support.

傳回

傳回目前安裝在系統上且支援指定的地區設定的語音的唯讀集合。Returns a read-only collection of the voices currently installed on the system that support the specified locale.

範例

下列範例是主控台應用程式的一部分, 它會初始化SpeechSynthesizer物件, 並將已安裝的語音清單輸出到主控台, 以支援 en-us 地區設定。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);  
    }  
  }  
}  
  

備註

如果未安裝的語音支援指定的地區設定, 則這個方法會傳回空集合。If none of the installed voices support the specified locale, this method returns an empty collection.

Microsoft Windows 和 System. Speech API 接受所有有效的語言國家/地區代碼。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. 隨附于 Microsoft Windows 7 的語音合成引擎可與下列語言國家/地區代碼搭配使用:The speech synthesis engines that shipped with Microsoft Windows 7 work with the following language-country codes:

  • en-us。en-US. 英文 (美國)English (United States)

  • zh-CN。zh-CN. 中文 (中國)Chinese (China)

  • zh-幼圓。zh-TW. 中文 (臺灣)Chinese (Taiwan)

也允許使用兩個字母的語言代碼, 例如 "en"。Two-letter language codes such as "en" are also permitted.

另請參閱

適用於