这是我的代码:
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
最佳答案
我决定进入语音 key 寄存器,在备份该 key 后,我删除了一个接一个的所有语音,每次都尝试输入代码,直到错误消失。错误是 Loquendo 的声音。 在那之后,我尝试恢复备份(所有声音)再次寻找错误并且......操作系统回答说无法写入一个值,因为它正在被另一个应用程序使用......这就是神奇的事情:一切正常!
关于c# - 语音合成器 "Input string was not in a correct format",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10304913/