SpeechSynthesizer.Voice 屬性

定義

取得目前 SpeechSynthesizer 物件之語音的相關資訊。

public:
 property System::Speech::Synthesis::VoiceInfo ^ Voice { System::Speech::Synthesis::VoiceInfo ^ get(); };
public System.Speech.Synthesis.VoiceInfo Voice { get; }
member this.Voice : System.Speech.Synthesis.VoiceInfo
Public ReadOnly Property Voice As VoiceInfo

屬性值

傳回目前 SpeechSynthesizer 物件之語音的相關資訊。

範例

下列範例會初始化 的 SpeechSynthesizer 實例,並取得目前語音的相關資訊。

using System;
using System.IO;
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())
      {

        // Get information about supported audio formats.
        string AudioFormats = "";
        foreach (SpeechAudioFormatInfo fmt in synth.Voice.SupportedAudioFormats)
        {
          AudioFormats += String.Format("{0}\n",
          fmt.EncodingFormat.ToString());
        }

        // Write information about the voice to the console.
        Console.WriteLine(" Name:          " + synth.Voice.Name);
        Console.WriteLine(" Culture:       " + synth.Voice.Culture);
        Console.WriteLine(" Age:           " + synth.Voice.Age);
        Console.WriteLine(" Gender:        " + synth.Voice.Gender);
        Console.WriteLine(" Description:   " + synth.Voice.Description);
        Console.WriteLine(" ID:            " + synth.Voice.Id);
        if (synth.Voice.SupportedAudioFormats.Count != 0)
        {
          Console.WriteLine(" Audio formats: " + AudioFormats);
        }
        else
        {
          Console.WriteLine(" No supported audio formats found");
        }

        // Get additional information about the voice.
        string AdditionalInfo = "";
        foreach (string key in synth.Voice.AdditionalInfo.Keys)
        {
          AdditionalInfo += String.Format("  {0}: {1}\n",
            key, synth.Voice.AdditionalInfo[key]);
        }

        Console.WriteLine(" Additional Info - " + AdditionalInfo);
        Console.WriteLine();
      }

      Console.WriteLine();
      Console.WriteLine("Press any key to exit...");
      Console.ReadKey();
    }
  }
}

備註

當您初始化新的 SpeechSynthesizer 時,它會使用預設的系統語音。 若要將 SpeechSynthesizer 物件設定為使用其中一個已安裝的語音合成語音,請使用 SelectVoiceSelectVoiceByHints 方法。 若要取得已安裝哪些語音的相關資訊,請使用 GetInstalledVoices 方法和 VoiceInfo 類別。

適用於

另請參閱