Search code examples
c#text-to-speech

SpeechSynthesizer.SelecVoice(string) Not working


I'm trying to run this code below, that is working fine with "(en-US, Helen)".

but when I try to change the language to "(pt-BR, Maria)", it gives me the exception that the voice isn't installed or is disabled.

I have run a piece of code that display all speech-languages available:

 Console.WriteLine("Installed voices -");
 foreach (InstalledVoice voice in synth.GetInstalledVoices())
 {
     VoiceInfo info = voice.VoiceInfo;
     Console.WriteLine(" Voice Name: " + info.Name + info.Culture + info.Description);
 }

and the output shows:

Voice Name: Microsoft David Desktopen-USMicrosoft David Desktop - English (United States)
Voice Name: Microsoft Zira Desktopen-USMicrosoft Zira Desktop - English (United States)
Voice Name: Microsoft Maria Desktoppt-BRMicrosoft Maria Desktop - Portuguese(Brazil)

Code to set the language:

using (var synth = new SpeechSynthesizer())
{
    synth.SelectVoice("Microsoft Server Speech Text to Speech Voice (pt-BR, Maria)");
    synth.Volume = 100;  // (0 - 100)
    synth.Rate = 0;     // (-10 - 10)
    synth.Speak("Central esta Off-Line");
}

EDIT:

Everything is installed fine, the packs, etc. The selection method is not working ( don't know why)... I posted the solution already, hope it helps people with the same problem. Cheers!


Solution

  • I managed to solve this, with this piece of code:

    synth.SelectVoiceByHints(VoiceGender.Female, VoiceAge.Adult, 0, CultureInfo.GetCultureInfo("pt-BR"));

    Aparently, Microsoft Solution is not working for me... well, that works. I'll leave here to help other people with this kind of problem. Thanks!