UNPKG

node-red-contrib-tts-ultimate

Version:

Transforms the text in speech and hear it using Sonos player or generate an audio file to be used with third parties nodes. Works with voices from Amazon, Google (without credentials as well), Microsoft TTS Azure, or your own voice. You can also only crea

232 lines (211 loc) 11.1 kB
<script type="text/javascript"> RED.nodes.registerType("ttsultimate-config", { category: 'config', defaults: { name: { value: "TTS Service" }, noderedipaddress: { value: "AUTODISCOVER", required: false, type: "text" }, noderedport: { value: "1980", required: false, type: "text" }, purgediratrestart: { value: "leave", required: false }, ttsservice: { value: "googletranslate", required: false }, TTSRootFolderPath: { value: "", required: false } }, credentials: { accessKey: { type: "text" }, secretKey: { type: "password" }, mssubscriptionKey: { type: "text" }, mslocation: { type: "text" } }, label: function () { return this.name || ""; }, oneditprepare: function () { var node = this; // 21/03/2020 Check if the node is the absolute first in the flow. In this case, it has no http server instatiaced // $.getJSON('ttsultimateGetEthAddress', (data) => { $("#pleaseDeploy").hide(); $("#allGUI").show(); // }).fail(function (jqxhr) { // $("#pleaseDeploy").show(); // $("#allGUI").hide(); // }); if (node.noderedipaddress === undefined) { // Put the default address of the machine $.getJSON('ttsultimateGetEthAddress', (data) => { $("#node-config-input-noderedipaddress").val(data); }); } if (typeof node.noderedport === "undefined") { // Put the default port $("#node-config-input-noderedport").val("1980"); } if (typeof node.purgediratrestart === "undefined") { // Put the default port $("#node-config-input-purgediratrestart").val("leave"); } // 22/12/2020 Hide parts of the ui // ########################################################## $("#node-config-input-ttsservice").change(function (e) { if ($("#node-config-input-ttsservice").val() == "polly") { $("#GoogleForm").hide(); $("#microsoftAzureForm").hide(); $("#pollyForm").show(); } else if ($("#node-config-input-ttsservice").val() == "googletts") { $("#microsoftAzureForm").hide(); $("#pollyForm").hide(); $("#GoogleForm").show(); } else if ($("#node-config-input-ttsservice").val() == "googletranslate") { $("#pollyForm").hide(); $("#GoogleForm").hide(); $("#microsoftAzureForm").hide(); } else if ($("#node-config-input-ttsservice").val() == "microsoftazuretts") { $("#pollyForm").hide(); $("#GoogleForm").hide(); $("#microsoftAzureForm").show(); } }); // ########################################################## // 022/12/2020 Upload file or files // ########################################################## $("#googleCredentialsPath").change(function (e) { var oFiles; oFiles = this.files; $.each(oFiles, function (i, file) { var fdata = new FormData(); fdata.append("googleCreds", file); $.ajax({ url: "ttsultimatesavegooglecredentialsfile", type: "POST", data: fdata, //add the FormData object to the data parameter processData: false, //tell jquery not to process data contentType: false, success: function (response, status, jqxhr) { // Refresh the combo // The only way is to wait some time, then refresh let myNotification = RED.notify("Your credential file has been saved in the ttsultimategooglecredentials folder (into your .node-red directory) with name googlecredentials.json\n WARNING: This file contains your credentials to access google cloud API. Please be aware of this!", { modal: true, fixed: true, type: 'info', buttons: [ { "text": "OK", "class": "primary", "click": function (e) { myNotification.close(); } }] }); }, error: function (jqxhr, status, errorMessage) { //handle error RED.notify("Problem saving credentials: " + errorMessage + ". PLEASE, SAVE THE NODE, DEPLOY AND REOPEN THIS WINDOW.", { modal: false, fixed: false, type: 'error' }); } }); }); }); // ########################################################## } }); </script> <script type="text/x-red" data-template-name="ttsultimate-config"> <div id="pleaseDeploy"> <p align="center"> THIS IS YOUR FIRST CONFIG-NODE<br/> AND I NEED TO CREATE SOME THINGS<br/> BEFORE LETTING YOU PROCEED.<br/><b>PLEASE SAVE, FULL DEPLOY <br/>AND RE-OPEN THIS WINDOW</b><br/> TO BE ABLE TO FINISH THE CONFIGURATION SETUP<br/> </p> </div> <div id="allGUI"> <div class="form-row"> <b>TTS Server configuration</b>&nbsp&nbsp&nbsp&nbsp<span style="color:red"><i class="fa fa-question-circle"></i>&nbsp<a target="_blank" href="https://github.com/Supergiovane/node-red-contrib-tts-ultimate"><u>Help online</u></a></span> <br/> <br/> </div> <div class="form-row"> <label for="node-config-input-name"><i class="fa fa-user"></i> Name</label> <input type="text" id="node-config-input-name"> </div> <div class="form-tips" style="margin-top: 8px;background-color:#ffcccc;text-align:center">If <b>YOU MUST RESTART NODE-RED</b><br/> AFTER EACH CHANGE IN THIS WINDOW!</div> <br/> <p><b>SONOS CONFIGURATION</b></p> <div class="form-row"> <label for="node-config-input-noderedipaddress"><i class="fa fa-globe"></i> Node-Red IP</label> <input type="text" id="node-config-input-noderedipaddress"> </div> <br/> <div class="form-row"> <label for="node-config-input-noderedport"><i class="fa fa-globe"></i> Host port</label> <input type="text" id="node-config-input-noderedport"> </div> <br/> <p><b>SPEECH CONFIGURATION</b></p> <div class="form-row"> <label for="node-config-input-ttsservice"><i class="fa fa-comments"></i> TTS Service</label> <select id="node-config-input-ttsservice"> <option value="polly">Amazon Polly</option> <option value="googletts">Google TTS</option> <option value="googletranslate">Google without authentication</option> <option value="microsoftazuretts">Microsoft Azure TTS</option> </select>&nbsp&nbsp<b><span style="color:red"><i class="fa fa-question-circle"></i>&nbsp<a target="_blank" href="https://github.com/Supergiovane/node-red-contrib-tts-ultimate"><u>Help configure</u></a></span> </div> <div id="pollyForm"> <div class="form-row"> <label for="node-config-input-accessKey"><i class="fa fa-user"></i> AWS Access key</label> <input type="text" id="node-config-input-accessKey"> </div> <div class="form-row"> <label for="node-config-input-secretKey"><i class="fa fa-user"></i> AWS Secret key</label> <input type="password" id="node-config-input-secretKey"> </div> </div> <div id="GoogleForm"> <div class="form-row"> <label><i class="fa fa-upload"></i> Google credentials file path</label> <input style="width:180px" id="googleCredentialsPath" type="file"> </div> </div> <div id="microsoftAzureForm"> <div class="form-row"> <label style="width:35%" for="node-config-input-mssubscriptionKey"><i class="fa fa-user"></i> Azure subscription key</label> <input style="width:58%" type="text" id="node-config-input-mssubscriptionKey"> </div> <div class="form-row"> <label style="width:35%" for="node-config-input-mslocation"><i class="fa fa-user"></i> Azure location (ex:westeurope)</label> <input style="width:58%" type="text" id="node-config-input-mslocation"> </div> </div> <div class="form-row"> <label for="node-config-input-purgediratrestart"><i class="fa fa-folder-o"></i> TTS Cache</label> <select id="node-config-input-purgediratrestart"> <option value="purge">Purge and delete the TTS cache folder at deploy or restart(default)</option> <option value="leave">Leave the TTS cache folder untouched (not suggested if you have less disk space)</option> </select> </div> <div class="form-row"> <label for="node-config-input-TTSRootFolderPath"><i class="fa fa-folder-o"></i> Cache root folder</label> <input type="text" id="node-config-input-TTSRootFolderPath" placeholder="The folder must exist. Leave blank for default"> </div> </div> </script> <script type="text/x-red" data-help-name="ttsultimate-config"> <p> <a href="https://www.paypal.me/techtoday" target="_blank"><img src='https://img.shields.io/badge/Donate-PayPal-blue.svg?style=flat-square' width='30%'></a> </p> <p> Configuration help is in the <a href="https://github.com/Supergiovane/node-red-contrib-tts-ultimate/blob/master/README.md">README</a><br/> </p> </script>