0

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!

  • Possible duplicate of [SpeechSynthesizer.SelectVoice() Fails with "No matching voice is installed or the voice was disabled"](https://stackoverflow.com/questions/34776593/speechsynthesizer-selectvoice-fails-with-no-matching-voice-is-installed-or-th) – Klaus Gütter Jan 09 '19 at 13:41
  • Nope, that didn't solve the problem at all... the language pack is installed, everything is fine. Weird enough, i think the problem is the MDNS method. however, i managed to solve using "by hints". i'll post the answer below. – Breno Almeida Jan 09 '19 at 13:49

2 Answers2

1

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!

1

I had a similar problem in winForms. This works for me in uwp:

using Windows.Media.SpeechSynthesis;
if (_voiceInfo == null)
{
    _voiceInfo =
        (
            from voice in SpeechSynthesizer.AllVoices
            where voice.Language == "fi-FI"
            select voice
        ).FirstOrDefault() ?? SpeechSynthesizer.DefaultVoice;
    textBlock.Text = _voiceInfo.Language;
}
Fourat
  • 2,366
  • 4
  • 38
  • 53