Freigeben über


Enumerating TTS Engines using System.Speech.Synthesizer

Here is a quick and dirty C# console application that will list out the installed TTS engines and associated properties.  Make sure you add System.Speech to your project's list of references.

 using System;
using System.Collections.Generic;
using System.Speech;
using System.Speech.Synthesis;
using System.Speech.AudioFormat;

namespace SelectVoice
{
  class SelectVoice
  {
    static void Main(string[] args)
    {
      Console.WriteLine("SelectVoice Example");
      SpeechSynthesizer ttsSynth = new SpeechSynthesizer();

      Console.WriteLine("Listing installed speech synthesizer voices...");
      foreach (InstalledVoice ttsVoice in ttsSynth.GetInstalledVoices())
      {
        Console.WriteLine("Name:\t{0}", ttsVoice.VoiceInfo.Name);
        Console.WriteLine("Desc:\t{0}", ttsVoice.VoiceInfo.Description);
        Console.WriteLine("Id:\t{0}", ttsVoice.VoiceInfo.Id);
        Console.WriteLine("Gender:\t{0}", ttsVoice.VoiceInfo.Gender);
        Console.WriteLine("Age:\t{0}", ttsVoice.VoiceInfo.Age);

        Console.WriteLine("Supported Audio Formats:");
        foreach (SpeechAudioFormatInfo audioFormat in ttsVoice.VoiceInfo.SupportedAudioFormats)
        {
          Console.WriteLine("\tEncodingFormat:\t{0}", audioFormat.EncodingFormat);
          Console.WriteLine("\tChannelCount:\t{0}", audioFormat.ChannelCount);
          Console.WriteLine("\tBits/sec:\t{0}", audioFormat.BitsPerSample);
          Console.WriteLine("\tAvg Bytes/sec:\t{0}", audioFormat.AverageBytesPerSecond);
          Console.WriteLine("\tSamples/sec:\t{0}", audioFormat.SamplesPerSecond);
          Console.WriteLine("\tBlockAlign:\t{0}", audioFormat.BlockAlign);
        }

        Console.WriteLine("Additional Information:");
        foreach(KeyValuePair<string, string> kvp in ttsVoice.VoiceInfo.AdditionalInfo)
          Console.WriteLine("\t{0}:  {1}", kvp.Key, kvp.Value);
        Console.WriteLine();
      }
    Console.WriteLine("Finished listing installed voices.");

    ttsSynth.SelectVoice("Microsoft Anna");
    ttsSynth.Speak("Greetings, my name is " + ttsSynth.Voice.Name);
    }
  }
}

Comments

  • Anonymous
    July 30, 2008
    HiI just send you a message through the mail contact page of this blog about System.Speech.Synthesizer.This implementation is not using the sapi 5 enumerator as he enumerate only the voices registered statically into the registry (under the Token key) and not the voices dynamically enumerated by third party Sapi5 compliant engine, using the TokenEnum key.Is it a bug, or a feature? :-)
  • Anonymous
    August 12, 2008
    My inquiry is vaguely related to that of Jean-Michel.I've done work with VR and TTS in the past and am now taking another look. Some of the speech engines out there are very good, and not expensive either. The nicer ones are 22KHz, SAPI5, and have large/complex grammars.How can we find all engines on the system and not just those registered as an "InstalledVoice"?How can we enumerate the capabilities of these commercial engines?  Or should we expect full documentation and examples from each provider?  I'm not sure how much latitude the engine developers have about which features are supported or how they're implemented.Will any SAPI5 engine work with SAPI5.3 or can I expect versioning issues and incompatibilities when trying to use System.Speech with these guys?How do I know how to make best use of these 200MB engines vs the smaller 20MB/16KHz ones?  In other words, how do I know whether to use XML tags to craft a phrase when there might be some method or property that might be easier or better suited?Maybe I'm looking at this wrong - maybe the large size of these engines is mostly for recognition and very little of it deviates from or augments the XML standards.As you can see, my problem is that I don't know what I don't know when it comes to finding a nice engine/voice and then developing around it. Any tips?  Good topic for a new blog entry?Not looking for "fish" here, just tell me where to fish and I'll be happy to do my bait my own hooks.Thanks.
  • Anonymous
    August 28, 2008
    The comment has been removed