7

I want to make a text to speech program for my interactive training set. I used the System.Speech library, but the voice is always female. I would like some sentences to be read with a male voice, and some to be read by a female voice. (These two voices are the only ones I need.)

I'm using Windows 8 Pro and Visual Studio 2010. I can see only one voice pack, the Microsoft Zira Desktop.

My code is as follows. How can I configure the use of a male voice?

SpeechSynthesizer synth = new SpeechSynthesizer();
synth.Rate = 1;
synth.Volume = 100;
synth.SelectVoiceByHints(VoiceGender.Male,VoiceAge.Adult);
synth.SpeakAsync(label18.Text);
4444
  • 3,541
  • 10
  • 32
  • 43
mertc.
  • 123
  • 1
  • 7
  • Perhaps other voices need to be installed on the system in question? – Greg D Jun 30 '14 at 15:53
  • 2
    Have you tried the `SelectVoice` method call, which accepts a VoiceGender argument string? Or have you verified by calling `GetInstalledVoices` that there are voices to match your specified hints? What Culture are you using? – pinkfloydx33 Jun 30 '14 at 15:56
  • i tried GetInstalledVoices with foreach (InstalledVoice voice in synth.GetInstalledVoices()) and it showed only Microsoft Zira, then i've 2 problem now :) 1) how can i install microsoft david desktop 2) if i will succeed install, how the program will run another pc which without microsoft david? sorry for my english :) – mertc. Jun 30 '14 at 16:25

1 Answers1

6

You first need to know which voices are installed, you can do this by GetInstalledVoices method of SpeechSynthesizer class: http://msdn.microsoft.com/en-us/library/system.speech.synthesis.speechsynthesizer.getinstalledvoices.aspx

Once you're sure that you've got a male voice installed, then you can simply switch by SelectVoiceByHints See: http://msdn.microsoft.com/en-us/library/ms586877

using (SpeechSynthesizer synthesizer = new SpeechSynthesizer())
{
    // show installed voices
    foreach (var v in synthesizer.GetInstalledVoices().Select(v => v.VoiceInfo))
    {
        Console.WriteLine("Name:{0}, Gender:{1}, Age:{2}",
          v.Description, v.Gender, v.Age);
    }

    // select male senior (if it exists)
    synthesizer.SelectVoiceByHints(VoiceGender.Male, VoiceAge.Senior);

    // select audio device
    synthesizer.SetOutputToDefaultAudioDevice();

    // build and speak a prompt
    PromptBuilder builder = new PromptBuilder();
    builder.AppendText("Found this on Stack Overflow.");
    synthesizer.Speak(builder);
}

See this for further explanation: how I can change the voice synthesizer gender and age in C#?

Community
  • 1
  • 1