我正在修改Scott Hanselman的BabySmash代码以支持其他语言。
- 我按照这些步骤安装了语音平台和新语言。
该语言现在显示在注册表中:
现在可以通过 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
.我已经验证了版本和
Microsoft.Speech.dll
语言包匹配。此代码适用于我已经安装的默认声音。
无奈之下,我什至尝试
System.Speech.Internal.Synthesis.VoiceSynthesis.GetVoice()
通过反射直接调用,但同样的错误。
我将不胜感激您能提供的任何帮助!谢谢。