我正在修改Scott Hanselman的BabySmash支持其他语言的代码。
- 我按照 these steps 安装了语音平台和新语言.
该语言现在显示在注册表中:
现在可以通过 Windows 选择和播放语言:
System.Speech.Synthesis.SpeechSynthesizer.GetInstalledVoices()
现在返回声音。- 但是
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);
我已尝试升级到
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Speech.dll
.我已经verified that the versions的
Microsoft.Speech.dll
和语言包匹配。此代码适用于我已安装的默认语音。
无奈之下,我什至尝试调用
System.Speech.Internal.Synthesis.VoiceSynthesis.GetVoice()
直接通过反射,但同样的错误。
我将非常感谢您提供的任何帮助!谢谢。
最佳答案
哈哈我觉得很特别:this post on Python实际上解决了我的问题:构建配置平台需要是x64,而不是任何CPU
!
关于c# - SpeechSynthesizer.SelectVoice() 失败并显示 "No matching voice is installed or the voice was disabled",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34776593/