SpeechSynthesizer.SelectVoice()与"失败是没有安装匹配的语音或声音被禁用" [英] SpeechSynthesizer.SelectVoice() Fails with "No matching voice is installed or the voice was disabled"
问题描述
我修改斯科特Hanselman的的的 BabySmash 代码来支持其他语言。
- 我安装了语音平台和一个新的每这些步骤。
-
语言现在显示在注册表中:
-
语言现在可以被Windows选择和播放:
-
System.Speech.Synthesis.SpeechSynthesizer.GetInstalledVoices()
现在返回的声音。 - 然而
SelectVoice()
下面的代码中引发错误的System.ArgumentException:无法设置的声音。没有匹配的声音安装或声音被禁用。
<预类=郎-CS prettyprint-覆盖>
串词= NULL;
SpeechSynthesizer讲话=新SpeechSynthesizer();
CultureInfo的keyboardCulture = System.Windows.Forms.InputLanguage.CurrentInputLanguage.Culture;
InstalledVoice neededVoice =讲话。 GetInstalledVoices(keyboardCulture).FirstOrDefault();
如果(neededVoice == NULL)
{
语句=不支持的语言;
}!
,否则如果(neededVoice .Enabled)
{
语句=语音已禁用;
}
,否则
{
speech.SelectVoice(neededVoice.VoiceInfo.Name);
}
speech.Speak(短语);
-
我试过升级到
C:\Program文件(x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\ 。v4.6.1\System.Speech.dll
-
我已经的证实,该版本,一>的
Microsoft.Speech.dll
和语言包匹配
-
此代码适用于我已经安装了默认的声音。
-
在绝望中,我甚至试图调用
System.Speech.Internal.Synthesis.VoiceSynthesis.GetVoice()
直接通过反射,但完全相同的错误。
我将不胜感激任何帮助,您可以提供!谢谢你。
另一种解决方案是安装(64)位的Microsoft Speech SDK平台和Microsoft服务器语音平台运行时的版本。我认为你已经安装了的(86)位和plataform尝试(64)位阅读。
我有同样的问题,你但对相反,这工作对我!
I am modifying Scott Hanselman's BabySmash code to support other languages.
- I installed the speech platform and a new language per these steps.
The language now shows up in the registry:
The language can now be selected and played by Windows:
System.Speech.Synthesis.SpeechSynthesizer.GetInstalledVoices()
now returns the voice.- However
SelectVoice()
in the code below throws the error "System.ArgumentException: Cannot set voice. No matching voice is installed or the voice was disabled."
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);
I've tried upgrading to
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Speech.dll
.I've verified that the versions of
Microsoft.Speech.dll
and the language pack match.This code works for the default voices I've already had installed.
In desperation, I've even tried invoking
System.Speech.Internal.Synthesis.VoiceSynthesis.GetVoice()
directly through reflection, but same exact error.
I would greatly appreciate any help you can provide! Thanks.
Another solution is to install (x64) bits version of Microsoft Speech Platform SDK and Microsoft Server Speech Platform Runtime. I think that you had installed (x86) bits of both and the plataform try to read it in (x64) bits.
I had the same problem that you but on the contrary and this works to me!
这篇关于SpeechSynthesizer.SelectVoice()与"失败是没有安装匹配的语音或声音被禁用"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!