SpeechSynthesizer.SelecVoice(字符串)不工作

SpeechSynthesizer.SelecVoice(string) Not working

我正在尝试 运行 下面的这段代码,它与“(en-US,Helen)”一起工作正常。

但是当我尝试将语言更改为“(pt-BR, Maria)”时,出现异常,提示语音未安装或已禁用。

我有 运行 一段显示所有可用语音语言的代码:

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

并且输出显示:

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)

设置语言的代码:

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");
}

编辑:

一切都安装好了,包等等。选择方法不起作用(不知道为什么)...我已经发布了解决方案,希望它能帮助遇到同样问题的人。干杯!

我设法用这段代码解决了这个问题:

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

显然,Microsoft 解决方案对我不起作用...好吧,那行得通。我会离开这里帮助其他人解决此类问题。谢谢!

我在 winForms 中遇到了类似的问题。这在 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;
}