SpeechSynthesizer.GetInstalledVoices Método

Definição

Devolve a coleção de vozes de síntese de voz (texto para fala) que estão atualmente instaladas no sistema.

Sobrecargas

Name Description
GetInstalledVoices()

Devolve todas as vozes de síntese de voz instaladas (texto para fala).

GetInstalledVoices(CultureInfo)

Devolve todas as vozes de síntese de voz instaladas (texto para fala) que suportam uma localização específica.

Observações

Quando uma aplicação chama GetInstalledVoices, o método verifica que cada uma das vozes (motores de texto para fala) encontrada no registo cumpre certos critérios mínimos. Para qualquer voz que falhe na verificação, GetInstalledVoices define a sua Enabled propriedade para False. Uma aplicação não pode selecionar uma voz cuja Enabled propriedade seja False. Normalmente, as aplicações não definem a propriedade de Enabled uma voz.

GetInstalledVoices()

Origem:
SpeechSynthesizer.cs
Origem:
SpeechSynthesizer.cs
Origem:
SpeechSynthesizer.cs
Origem:
SpeechSynthesizer.cs

Devolve todas as vozes de síntese de voz instaladas (texto para fala).

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)

Devoluções

Devolve uma coleção de apenas leitura das vozes atualmente instaladas no sistema.

Exemplos

O exemplo seguinte faz parte de uma aplicação de consola que inicializa um SpeechSynthesizer objeto e envia para a consola uma lista das vozes instaladas (motores para síntese de voz) e demonstra a informação disponível para cada voz.

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

Observações

Uma voz é um motor para síntese de voz (texto para voz ou TTS) que está instalado no sistema.

Ver também

Aplica-se a

GetInstalledVoices(CultureInfo)

Origem:
SpeechSynthesizer.cs
Origem:
SpeechSynthesizer.cs
Origem:
SpeechSynthesizer.cs
Origem:
SpeechSynthesizer.cs

Devolve todas as vozes de síntese de voz instaladas (texto para fala) que suportam uma localização específica.

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)

Parâmetros

culture
CultureInfo

O local que a voz deve suportar.

Devoluções

Devolve uma coleção de apenas leitura das vozes atualmente instaladas no sistema que suportam a localização especificada.

Exemplos

O exemplo seguinte faz parte de uma aplicação de consola que inicializa um SpeechSynthesizer objeto e envia para a consola uma lista das vozes instaladas que suportam o local 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);
    }
  }
}

Observações

Se nenhuma das vozes instaladas suportar a localização especificada, este método devolve uma coleção vazia.

Microsoft Windows e a API System.Speech aceitam todos os códigos válidos de língua-país. Para realizar o texto para fala usando a linguagem especificada na propriedade Cultura, deve ser instalado um motor de síntese de voz que suporte esse código língua-país. Os motores de síntese de voz que vieram com Microsoft Windows 7 funcionam com os seguintes códigos de língua e país:

  • en-US. Inglês (Estados Unidos)

  • zh-CN. Chinês (China)

  • zh-TW. Chinês (Taiwan)

Códigos linguísticos de duas letras, como "en", também são permitidos.

Ver também

Aplica-se a