Speech synthesizer "The input string was not in the correct format"

Here is my code:

string _message = "Hello world.";
SpeechSynthesizer _synth = new SpeechSynthesizer();
Prompt _prompt = new Prompt(_message);
_synth.Speak(_prompt);

I can’t understand for life what exactly causes this error:

"The input string was not in the correct format."

The line causing this error is when I call _synth.Speak(_prompt);
EDIT: I tried this code on my desktop computer and it works fine, so something is wrong with my installation on my laptop. However, I'm not too sure how to fix this ...

EDIT:

Stack:

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
+3
source share
4 answers

, . HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens. . MS-Anna, , .

- \, , . "409", LCID .

, , . , Windows Vista . superuser.com, . DVD.

+1

, , , . Loquendo. ( ), , ... OS , , ... : !

+3

. , API . Loquendo TTS. PROCMON , , (). API , . ( "40c" ) FormatException:

[HKEY_LOCAL_MACHINE \ SOFTWARE \ Wow6432Node \ Microsoft \ Speech \ Voices \ Tokens \ LQBernard \ Properties] "Language" = "40s"

changed to:

"Language" = "40" (trailing character "c" is deleted).

I repeated this process for my installed French Loquendo TTS language packs (Bernard and Juliette), and this resolved this for me.

+1
source

This may not be the source of your problem, but it looks like in the API you can just call

new SpeechSynthesizer().Speak("Hello world.");

and avoid all extra code ... did you try to delete the period?

0
source

All Articles