下面是我的代码:
string _message = "Hello world.";
SpeechSynthesizer _synth = new SpeechSynthesizer();
Prompt _prompt = new Prompt(_message);
_synth.Speak(_prompt);我无论如何也找不出到底是什么导致了这个错误:
“输入字符串的格式不正确。”
导致此错误的代码行是当我调用_synth.Speak(_prompt);时
编辑:我已经在我的台式电脑上尝试了这段代码,它工作得很好,所以我在笔记本电脑上的安装出现了问题。我还是不太确定该怎么解决这个问题。
编辑:
堆栈跟踪:
System.FormatException: Input string was not in a correct format.
at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffe
r& number, NumberFormatInfo info, Boolean parseDecimal)
at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo in
fo)
at System.Speech.Internal.SapiAttributeParser.GetCultureInfoFromLanguageStrin
g(String valueString)
at System.Speech.Synthesis.VoiceInfo..ctor(VoiceObjectToken token)
at System.Speech.Internal.Synthesis.VoiceSynthesis.BuildInstalledVoices(Voice
Synthesis voiceSynthesizer)
at System.Speech.Internal.Synthesis.VoiceSynthesis..ctor(WeakReference speech
Synthesizer)
at System.Speech.Synthesis.SpeechSynthesizer.get_VoiceSynthesizer()
at System.Speech.Synthesis.SpeechSynthesizer.Speak(Prompt prompt)
at TTSTesting.Program.Speak(String _message) in C:\Users\ctanaka\Desktop\TTST
esting\TTSTesting\Program.cs:line 22发布于 2012-04-25 10:57:23
您的机器注册表混乱,其中包含无效的语音配置数据。相关的关键字是HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens。在下面,你会发现安装的声音。一台英文机器通常有MS-Anna,但如果您购买更多,还可能有其他的。
乱七八糟的值是Attribute\Language,它不是应该的十六进制数。如"409",英语的LCID的十六进制值。
您可以通过卸载您添加的语音、删除注册表中的不良语音或修复语言值来修复它。重新安装很棘手,这是Vista和更高版本的Windows安装程序的一部分。如果你不能修复它,你将需要superuser.com的帮助。或者你的设置DVD。
发布于 2012-11-07 20:37:51
我决定进入voices关键字寄存器,并在备份该关键字后,逐个删除每次尝试代码的所有声音,直到错误消失。错误出现在Loquendo的声音中。在那之后,我尝试恢复备份(所有声音),再次查找错误...操作系统回答说无法写入值,因为它正在被另一个应用程序使用...这就是神奇之处:一切都运行得很好!
发布于 2012-10-17 10:53:07
我也有同样的问题。Hans Passant告诉我们这个API会解析注册表中的字符串值来检测安装的语言。我也安装了Loquendo TTS语言包。使用PROCMON和试错法,我设法找出了导致错误的确切注册表项(语言)。API要求此字符串仅包含用于整数转换的数字字符。尝试解析和转换此字符串("40c")会触发FormatException:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Speech\Voices\Tokens\LQBernard\Attributes "Language"="40c“
更改为:
"Language"="40“(去掉尾随的'c‘字符)。
我对我安装的法语Loquendo TTS语言包(Bernard和Juliette)重复了这个过程,这为我解决了这个问题。
https://stackoverflow.com/questions/10304913
复制相似问题