SpeechSynthesizer.GetInstalledVoices 方法

定义

返回系统上当前安装的语音合成(文字到语音)语音的集合。

重载

GetInstalledVoices()

返回所有安装的语音合成(文字到语音)语音。

GetInstalledVoices(CultureInfo)

返回支持特定区域设置的所有安装的语音合成(文字到语音)语音。

注解

当应用程序调用时 GetInstalledVoices ,该方法将验证每个声音 (的文本到语音转换引擎是否在注册表中找到) 满足某些最低标准。 对于验证失败的任何语音, GetInstalledVoices 将其 Enabled 属性设置为 False 。 应用程序无法选择其 Enabled 属性为的声音 False 。 通常,应用程序不会设置语音的 Enabled 属性。

GetInstalledVoices()

返回所有安装的语音合成(文字到语音)语音。

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)

返回

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

返回支持特定区域设置的所有安装的语音合成(文字到语音)语音。

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

语音必须支持的区域设置。

返回

ReadOnlyCollection<InstalledVoice>

返回当前安装在支持指定区域设置的系统的语音的只读集合。

示例

下面的示例是一个控制台应用程序的一部分,该应用程序初始化 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 和 Speech API 接受所有有效的语言-国家/地区代码。 若要使用 Culture 属性中指定的语言执行文本到语音转换,必须安装支持该语言-国家/地区代码的语音合成引擎。 Microsoft Windows 7 随附的语音合成引擎使用以下语言-国家/地区代码:

  • en-us。 英语(美国)

  • zh-chs-CN。 中文(中国)

  • zh-chs-幼圆。 中文(台湾)

还允许使用两个字母的语言代码,例如 "en"。

另请参阅

适用于