SpeechSynthesizer.GetInstalledVoices 方法

定義

傳回目前已安裝在系統上的語音合成 (文字轉換語音) 語音集合。

多載

GetInstalledVoices()

傳回所有已安裝的語音合成 (文字轉換語音) 語音。

GetInstalledVoices(CultureInfo)

傳回所有已安裝的語音合成 (支援特定地區設定的文字轉換語音) 語音。

備註

當應用程式呼叫 GetInstalledVoices 時,此方法會驗證每個語音 (引擎是否適用于文字轉換語音的引擎,) 它在登錄中找到符合特定最低準則。 針對任何失敗驗證的語音, GetInstalledVoices 將其 Enabled 屬性設定為 False 。 應用程式無法選取其屬性為 FalseEnabled 語音。 一般而言,應用程式不會設定語音的屬性 Enabled

GetInstalledVoices()

來源:
SpeechSynthesizer.cs
來源:
SpeechSynthesizer.cs
來源:
SpeechSynthesizer.cs

傳回所有已安裝的語音合成 (文字轉換語音) 語音。

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)

傳回

傳回目前安裝在系統上的語音的唯讀集合。

範例

下列範例是主控台應用程式的一部分,它會初始化 SpeechSynthesizer 物件並輸出至主控台,其中已安裝的語音 (引擎清單,用於語音合成) ,並示範每個語音可用的資訊。

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) 。

另請參閱

適用於

GetInstalledVoices(CultureInfo)

來源:
SpeechSynthesizer.cs
來源:
SpeechSynthesizer.cs
來源:
SpeechSynthesizer.cs

傳回所有已安裝的語音合成 (支援特定地區設定的文字轉換語音) 語音。

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

語音必須支援的地區設定。

傳回

傳回目前安裝在系統上且支援指定的地區設定的語音的唯讀集合。

範例

下列範例是主控台應用程式的一部分,可初始化 SpeechSynthesizer 物件並輸出至主控台,其中包含支援 en-US 地區設定的已安裝語音清單。

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

備註

如果任何已安裝的語音都不支援指定的地區設定,這個方法會傳回空的集合。

Microsoft Windows 和 System.Speech API 接受所有有效的語言國家/地區代碼。 若要使用 Culture 屬性中指定的語言執行文字轉換語音,必須安裝支援該語言國家/地區代碼的語音合成引擎。 隨附Microsoft Windows 7 的語音合成引擎會使用下列語言國家/地區代碼:

  • en-US. 英文 (美國)

  • zh-CN. 簡體中文

  • zh-TW。 中文 (台灣)

也允許使用雙字母語言代碼,例如 「en」。

另請參閱

適用於