SpeechSynthesizer.SelectVoice()失败,“未安装匹配的语音或语音被禁用”

我正在修改Scott Hanselman的BabySmash代码以支持其他语言。

  1. 我按照这些步骤安装了语音平台和新语言。
  2. 该语言现在显示在注册表中:

    在此处输入图像描述

  3. 现在可以通过Windows选择和播放该语言:

    在此处输入图像描述

  4. System.Speech.Synthesis.SpeechSynthesizer.GetInstalledVoices()现在返回语音。

  5. 但是,下面的代码中的SelectVoice()会引发错误“System.ArgumentException:无法设置语音。未安装匹配的语音或语音被禁用”。
 string phrase = null; SpeechSynthesizer speech = new SpeechSynthesizer(); CultureInfo keyboardCulture = System.Windows.Forms.InputLanguage.CurrentInputLanguage.Culture; InstalledVoice neededVoice = speech.GetInstalledVoices(keyboardCulture).FirstOrDefault(); if (neededVoice == null) { phrase = "Unsupported Language"; } else if (!neededVoice.Enabled) { phrase = "Voice Disabled"; } else { speech.SelectVoice(neededVoice.VoiceInfo.Name); } speech.Speak(phrase); 
  1. 我已经尝试升级到C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Speech.dll

  2. 我已经validation了Microsoft.Speech.dll和语言包的版本是否匹配。

    在此处输入图像描述

  3. 此代码适用于我已安装的默认语音。

  4. 无奈之下,我甚至尝试通过reflection直接调用System.Speech.Internal.Synthesis.VoiceSynthesis.GetVoice() ,但同样精确的错误。

非常感谢您提供的任何帮助! 谢谢。

哈哈我觉得特别: 这篇关于Python的文章实际上解决了我的问题:构建配置平台需要是x64 ,而不是Any CPU

另一种解决方案是安装(x64)位版本的Microsoft Speech Platform SDK和Microsoft Server Speech Platform Runtime。 我认为你已经安装了两个(x86)位,并且plataform尝试用(x64)位读取它。

我有同样的问题,但相反,这对我有用!

在我的情况下,我需要使用Microsoft.Speech.Synthesis而不是库System.Speech.Synthesis 。 为此,我们需要转到VisualStudio上的解决方案资源管理器 – >引用和浏览Microsoft.Speech.dll

 using Microsoft.Speech.Synthesis; 

之后,您将拥有其他运行时语言。

  SpeechSynthesizer synth = new SpeechSynthesizer(); // Output information about all of the installed voices. foreach (InstalledVoice voice in synth.GetInstalledVoices()) { VoiceInfo info = voice.VoiceInfo; Console.WriteLine(" Name: " + info.Name); Console.WriteLine(" Culture: " + info.Culture); Console.WriteLine(" Age: " + info.Age); Console.WriteLine(" Gender: " + info.Gender); Console.WriteLine(" Description: " + info.Description); Console.WriteLine(" ID: " + info.Id); } 

将用户身份更改为Localsystem解决了我的问题! 在此处输入图像描述