InstalledVoice 類別

定義

包含安裝在 Windows 中語音合成聲音的相關資訊。

public ref class InstalledVoice
public class InstalledVoice
type InstalledVoice = class
Public Class InstalledVoice
繼承
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();  
    }  
  }  
}  

備註

使用此類別來取得已安裝語音的相關資訊,包括其文化特性、名稱、性別、年齡,以及是否啟用。

若要使用 屬性中指定的 Culture 語言來執行文字轉換語音,必須安裝支援該語言國家/地區代碼的語音合成引擎。 隨附于 Microsoft Windows 7 的語音合成引擎可搭配下列語言國家/地區代碼使用:

  • en-US. 英文 (美國)

  • zh-CN. 簡體中文

  • zh-TW。 中文 (台灣)

也允許兩個字母的語言代碼,例如 「en」。

屬性

Enabled

取得或設定語音是否可用來產生語音。

VoiceInfo

取得有關語音的資訊,例如文化特性、名稱、性別和年齡。

方法

Equals(Object)

判斷指定的物件是否為 InstalledVoice 執行個體並等於目前 InstalledVoice 執行個體。

GetHashCode()

提供 InstalledVoice 物件的雜湊碼。

GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於