简体   繁体   English

不带浏览器GUI的文本语音转换

[英]Text-To-Speech without browser GUI

I have been designing in HTML to create an application that has a GUI. 我一直在设计HTML以创建具有GUI的应用程序。 I have created a few scripts for this - particularly one that uses the browser window Speech Synthesis Utterance. 我为此创建了一些脚本-尤其是使用浏览器窗口“语音合成话语”的脚本。

Suddenly, however, the scope of the project has changed and I need to do away with the GUI, but keep the TTS script running as a background process. 但是,突然之间,项目范围发生了变化,我需要取消GUI,但是要让TTS脚本作为后台进程运行。 I'm still quite new to programming, so I tried opening the script with node.js, but it didn't work like that. 我对编程还是很陌生,所以我尝试使用node.js打开脚本,但它不能那样工作。 The utterance is programmed to read a certain xml file. 话语被编程为读取某个xml文件。 So essentially, all I want to do is to do away with the HTML browser aspect, and keep the javascript. 因此,从本质上讲,我要做的就是放弃HTML浏览器方面的内容,并保留javascript。 Is this possible? 这可能吗? Does anyone have any suggestions on how I could approach this? 有人对我该如何处理有任何建议吗?

I've tried opening the script solely in node.js I've looked into element.js but it doesn't "seem" to be what I am after. 我已经尝试过仅在node.js中打开脚本,而我已经查看了element.js,但似乎并没有成为我所追求的。

            var msg = new SpeechSynthesisUtterance("Testing");


            var voices = window.speechSynthesis.getVoices();
            var voice = speechSynthesis.getVoices();
            speechSynthesis.getVoices().forEach(function(voice) {
                console.log(voice.name, voice.default ? voice.default : '');
            });

            msg.pitch = 1.1;
            msg.volume = 1;
            msg.rate = 0.85;
            msg.lang = 'en-US';
            msg.voice = voices[1];
            window.speechSynthesis.speak(msg);

Actual results - Opens a web browser and begins talking (there's a html file) Expected results I want - No web browser, just talk when the file is opened (maybe?) 实际结果-打开Web浏览器并开始交谈(有一个html文件)我想要的预期结果-没有Web浏览器,只是在打开文件时交谈(也许?)

Try Electron with a frameless transparent window. 尝试使用无框透明窗口的Electron。

Electron packages up Node and Chromium for desktop applications. Electron将Node和Chromium打包为桌面应用程序。

I just tried this out and it worked for me: 我只是尝试了一下,对我有用:

git clone https://github.com/electron/electron-quick-start
# Go into the repository
cd electron-quick-start
# Install dependencies
npm install

Edit renderer.js and insert your code above. 编辑renderer.js并在上面插入代码。

Edit the window in main.js 在main.js中编辑窗口

  mainWindow = new BrowserWindow({
      width: 800,
      height: 600,
      frame: false,
      transparent: true,
      webPreferences: {
         preload: path.join(__dirname, 'preload.js')
      }
  })

Then make everything blank in index.html 然后在index.html中将所有内容空白

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM