gpt4 book ai didi

javascript - Powershell西里尔文通过node js输入编码

转载 作者:太空宇宙 更新时间:2023-11-03 22:27:22 24 4
gpt4 key购买 nike

我试图制作西里尔文文本转语音 Node js 模块。

我使用node-powershell运行 .NET TTS 命令。它可以很好地处理拉丁符号,但不会对任何西里尔符号产生 react 。

但是,如果我直接向 Powershell 控制台输入命令 - 它对于西里尔字母和拉丁符号都可以正常工作。 enter image description here

所以我做了一个解决方案,问题点是node.js输出编码。

Node.js 脚本:

var sayWin = (text) => {
var Shell = require('node-powershell');
var shell = new Shell({
inputEncoding: 'binary' //tried different endcoding
});
shell.addCommand('Add-Type -AssemblyName System.speech');
shell.addCommand('$speak = New-Object System.Speech.Synthesis.SpeechSynthesizer');
shell.addCommand('$speak.Speak("' + text + '")');
shell.on('output', data => {
console.log("data", data);
});
return shell.invoke();
}

sayWin('latin'); //talk

sayWin('кирилица'); //silence

sayWin('\ufeffкирилица'); //silence trying with BOM

请注意,您可能需要安装 Windows TTS 语音包并将其选择为默认系统语音才能播放西里尔文字(我之前已经这样做过)。

最佳答案

可能的解决方案之一是将西里尔文字音译为拉丁文字。它有效,但与预期结果相去甚远(单词发音不太好)。

var transliterate = function(word) {
var a = { "Ё": "YO", "Й": "I", "Ц": "TS", "У": "U", "К": "K", "Е": "E", "Н": "N", "Г": "G", "Ш": "SH", "Щ": "SCH", "З": "Z", "Х": "H", "Ъ": "'", "ё": "yo", "й": "i", "ц": "ts", "у": "u", "к": "k", "е": "e", "н": "n", "г": "g", "ш": "sh", "щ": "sch", "з": "z", "х": "h", "ъ": "'", "Ф": "F", "Ы": "I", "В": "V", "А": "a", "П": "P", "Р": "R", "О": "O", "Л": "L", "Д": "D", "Ж": "ZH", "Э": "E", "ф": "f", "ы": "i", "в": "v", "а": "a", "п": "p", "р": "r", "о": "o", "л": "l", "д": "d", "ж": "zh", "э": "e", "Я": "Ya", "Ч": "CH", "С": "S", "М": "M", "И": "yi", "Т": "T", "Ь": "'", "Б": "B", "Ю": "YU", "я": "ya", "ч": "ch", "с": "s", "м": "m", "и": "yi", "т": "t", "ь": "'", "б": "b", "ю": "yu" };
return word.split('').map(function(char) {
return a[char] || char;
}).join("");
}

var sayWin = (text) => {

text = /[а-яА-ЯЁё]/.test(text) ? transliterate(text) : text;

var shell = new Shell({
inputEncoding: 'binary'
});
shell.addCommand('Add-Type -AssemblyName System.speech');
shell.addCommand('$speak = New-Object System.Speech.Synthesis.SpeechSynthesizer');
shell.addCommand('$speak.Speak("' + text + '")');
shell.on('output', data => {
console.log("data", data);
});
shell.on('err', err => {
console.log("err", err);
});
shell.on('end', code => {
console.log("code", code);
});
return shell.invoke().then(output => {
shell.dispose()
});
}

关于javascript - Powershell西里尔文通过node js输入编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43792612/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com