我正在修改斯科特·汉斯曼的BabySmash代码以支持其他语言。
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()
,但是同样的错误。我非常感谢您能提供的任何帮助!谢谢。
发布于 2022-05-04 12:01:40
问题是,有些声音并不是所有申请都有登记的。这里有一篇很好的文章:https://www.ghacks.net/2018/08/11/unlock-all-windows-10-tts-voices-system-wide-to-get-more-of-them/
但是对于那些在上面的链接不起作用的时候找到这个答案的人来说:
其中涉及两个注册表项。
第一个是在使用GetInstalledVoices() API调用查询时使用的。第二个被Windows设置应用程序使用。
要使未列出的声音可用于GetInstalledVoices(),您需要将所需声音的数据从Speech_OneCore复制到语音节点(如果需要,则将其x86对应)复制到语音节点。
现在它应该可以工作了(可能需要重新启动)
https://stackoverflow.com/questions/34776593
复制相似问题