p-groarke / wsay

Windows "say"
BSD 3-Clause "New" or "Revised" License
141 stars 11 forks source link

Export as string instead of unicode for devices and speakers #9

Closed mandray closed 3 years ago

mandray commented 3 years ago

Is there a way to export as a normal string vs unicode. Trying to use this library through node.js and when I exec it it's returning unicode instead of a string for devices and speakers

p-groarke commented 3 years ago

Yes the library must return "windows strings" aka wstring aka unicode aka "fake" utf-16 :)

Do you have string conversions in node.js? You'd want utf-16/unicode to utf-8. Maybe this helps? https://www.npmjs.com/package/encoding I'm not a node js user so 🤞

If you can use c++ from node, wsay links with my fea library that contains string conversion functions. Though they aren't the most advanced (just wrappers on top of standard c++ conversions). See : https://github.com/p-groarke/fea_libs/blob/9fa730e352559faeb1651e1f4fe1d1fd3f1f28c4/include_cpp17/fea/utils/string.hpp#L490

Hope that helps, good day.

mandray commented 3 years ago

That did it, super simple with encoding. Here's a piece of the code in case anyone else comes here in the future:

const encoding = require('encoding');
const stdout = await execShellCommand('say --list_devices');
let str = encoding.convert(stdout, 'UTF-8', 'UTF-16');
str.toString();