DougHamil / DragonbornSpeaksNaturally

SkyrimVR mod for dialogue and other voice control
MIT License
20 stars 21 forks source link

Fix non-ASCII characters garbled between stdin/stdout #1

Closed YihaoPeng closed 6 years ago

YihaoPeng commented 6 years ago

dsn_plugin sent its command as UTF-8 encoded but dsn_service recieved it by ANSI (it will be GBK/cp936 when the system language is Simplified Chinese). So any non-ASCII characters will be garbled and speech recognition does not work at all when your game language is Traditional Chinese or Simplified Chinese.

I fixed the issue by adding a new param --encoding to dsn_service and set it be UTF-8 when dsn_plugin starting the service.

Now dsn_service is a console application because a Windows application cannot set InputEncoding, a System.IO.IOException: invalid handle will be threw.

And, because dsn_service is a console application, we can run it directly and input our commands to test. (Without the param, both console and dsn_service's encoding are ANSI so characters garbled will not happen.)

It has no additional disadvantages. I have modified the dsn_plugin to hide the console window. And when Skyrim exited, dsn_service can exit normally.

Now it works well with my SkyrimVR and Chinese Translation Mod. Official Traditional Chinese and English work well too.

DougHamil commented 6 years ago

Thank you! I'll do some quick manual testing to make sure there are no regressions and upload a new version to Nexus.

I got stuck on the "System.IO.IOException: invalid handle" when setting the InputEncoding and hadn't found a way to fix that.