node-red-contrib-tts-ultimate 2.0.2 → 2.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,15 @@
2
2
 
3
3
  [![Donate via PayPal](https://img.shields.io/badge/Donate-PayPal-blue.svg?style=flat-square)](https://www.paypal.me/techtoday)
4
4
 
5
+ <p>
6
+ <b>Version 2.0.4</b> August 2023<br/>
7
+ - Removed unused new AWS api.<br/>
8
+ - Updated old AWS api to the latest.<br/>
9
+ </p>
10
+ <p>
11
+ <b>Version 2.0.3</b> August 2023<br/>
12
+ - Fixed duplicated filenames.<br/>
13
+ </p>
5
14
  <p>
6
15
  <b>Version 2.0.2</b> August 2023<br/>
7
16
  - NEW: added options for changing Elevenlabs voice settings.<br/>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-tts-ultimate",
3
- "version": "2.0.2",
3
+ "version": "2.0.4",
4
4
  "description": "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, ElevenLabs.io TTS or your own voice. You can also only create a TTS file to be read by third party nodes. Update of the popular SonosPollyTTS node.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -40,8 +40,8 @@
40
40
  },
41
41
  "homepage": "https://github.com/Supergiovane/node-red-contrib-tts-ultimate",
42
42
  "dependencies": {
43
- "aws-sdk": "2.1404.0",
44
- "@aws-sdk/client-polly":"3.215.0",
43
+ "aws-sdk": "2.1444.0",
44
+
45
45
  "fs": "0.0.1-security",
46
46
  "sonos": "1.14.1",
47
47
  "formidable": "1.2.2",
@@ -564,26 +564,26 @@ module.exports = function (RED) {
564
564
 
565
565
 
566
566
  while (node.tempMSGStorage.length > 0) {
567
- node.currentMSGbeingSpoken = node.tempMSGStorage[0];// Advise the whole node of the currently spoken MSG
567
+ node.currentMSGbeingSpoken = node.tempMSGStorage.shift()//node.tempMSGStorage[0];// Advise the whole node of the currently spoken MSG
568
568
  const msg = node.currentMSGbeingSpoken.payload.toString(); // Get the text to be spoken
569
- node.tempMSGStorage.splice(0, 1); // Remove the first item in the array
570
- var sFileToBePlayed = "";
569
+ //node.tempMSGStorage.splice(0, 1); // Remove the first item in the array
570
+ node.sFileToBePlayed = "";
571
571
  node.setNodeStatus({ fill: "gray", shape: "ring", text: "Read " + msg });
572
572
 
573
573
  // 04/12/2020 check what really is the file to be played
574
574
  if (msg.toLowerCase().startsWith("http://") || msg.toLowerCase().startsWith("https://")) {
575
575
  RED.log.info('ttsultimate: HTTP filename: ' + msg);
576
- sFileToBePlayed = msg;
576
+ node.sFileToBePlayed = msg;
577
577
  } else if (msg.indexOf("OwnFile_") !== -1) {
578
578
  RED.log.info('ttsultimate: OwnFile .MP3, skip tts, filename: ' + msg);
579
- sFileToBePlayed = path.join(node.userDir, "ttspermanentfiles", msg);
579
+ node.sFileToBePlayed = path.join(node.userDir, "ttspermanentfiles", msg);
580
580
  } else if (msg.indexOf("Hailing_") !== -1) {
581
581
  RED.log.info('ttsultimate: Hailing .MP3, skip tts, filename: ' + msg);
582
- sFileToBePlayed = path.join(node.userDir, "hailingpermanentfiles", msg);
582
+ node.sFileToBePlayed = path.join(node.userDir, "hailingpermanentfiles", msg);
583
583
  } else {
584
584
  try {
585
585
  // No file in cache. Download from tts service
586
- var data;
586
+ var data = undefined;
587
587
  if (node.server.ttsservice === "polly") {
588
588
  var params = {
589
589
  OutputFormat: "mp3",
@@ -599,9 +599,9 @@ module.exports = function (RED) {
599
599
  params.VoiceId = node.voiceId;
600
600
  }
601
601
  // Download or read from cache
602
- sFileToBePlayed = getFilename(msg, params);
603
- sFileToBePlayed = path.join(node.userDir, "ttsfiles", sFileToBePlayed);
604
- if (!fs.existsSync(sFileToBePlayed)) {
602
+ node.sFileToBePlayed = getFilename(msg, params);
603
+ node.sFileToBePlayed = path.join(node.userDir, "ttsfiles", node.sFileToBePlayed);
604
+ if (!fs.existsSync(node.sFileToBePlayed)) {
605
605
  node.setNodeStatus({ fill: 'blue', shape: 'ring', text: 'Download using' + node.server.ttsservice });
606
606
  data = await synthesizeSpeechPolly([node.server.polly, params]);
607
607
  } else {
@@ -618,9 +618,9 @@ module.exports = function (RED) {
618
618
  params.input = node.ssml === false ? { text: msg } : { ssml: msg };
619
619
 
620
620
  // Download or read from cache
621
- sFileToBePlayed = getFilename(msg, params);
622
- sFileToBePlayed = path.join(node.userDir, "ttsfiles", sFileToBePlayed);
623
- if (!fs.existsSync(sFileToBePlayed)) {
621
+ node.sFileToBePlayed = getFilename(msg, params);
622
+ node.sFileToBePlayed = path.join(node.userDir, "ttsfiles", node.sFileToBePlayed);
623
+ if (!fs.existsSync(node.sFileToBePlayed)) {
624
624
  node.setNodeStatus({ fill: 'blue', shape: 'ring', text: 'Download using' + node.server.ttsservice });
625
625
  data = await synthesizeSpeechGoogleTTS([node.server.googleTTS, params]);
626
626
  } else {
@@ -636,9 +636,9 @@ module.exports = function (RED) {
636
636
  };
637
637
 
638
638
  // Download or read from cache
639
- sFileToBePlayed = getFilename(msg, params);
640
- sFileToBePlayed = path.join(node.userDir, "ttsfiles", sFileToBePlayed);
641
- if (!fs.existsSync(sFileToBePlayed)) {
639
+ node.sFileToBePlayed = getFilename(msg, params);
640
+ node.sFileToBePlayed = path.join(node.userDir, "ttsfiles", node.sFileToBePlayed);
641
+ if (!fs.existsSync(node.sFileToBePlayed)) {
642
642
  node.setNodeStatus({ fill: 'blue', shape: 'ring', text: 'Download using' + node.server.ttsservice });
643
643
  data = await synthesizeSpeechGoogleTranslate(node.server.googleTranslateTTS, params);
644
644
  } else {
@@ -652,9 +652,9 @@ module.exports = function (RED) {
652
652
  };
653
653
 
654
654
  // Download or read from cache
655
- sFileToBePlayed = getFilename(msg, params);
656
- sFileToBePlayed = path.join(node.userDir, "ttsfiles", sFileToBePlayed);
657
- if (!fs.existsSync(sFileToBePlayed)) {
655
+ node.sFileToBePlayed = getFilename(msg, params);
656
+ node.sFileToBePlayed = path.join(node.userDir, "ttsfiles", node.sFileToBePlayed);
657
+ if (!fs.existsSync(node.sFileToBePlayed)) {
658
658
  node.setNodeStatus({ fill: 'blue', shape: 'ring', text: 'Download using' + node.server.ttsservice });
659
659
  data = await synthesizeSpeechMicrosoftAzureTTS(node.server.microsoftAzureTTS, params);
660
660
  } else {
@@ -672,9 +672,9 @@ module.exports = function (RED) {
672
672
  }
673
673
  };
674
674
  // Download or read from cache
675
- sFileToBePlayed = getFilename(msg, params);
676
- sFileToBePlayed = path.join(node.userDir, "ttsfiles", sFileToBePlayed);
677
- if (!fs.existsSync(sFileToBePlayed)) {
675
+ node.sFileToBePlayed = getFilename(msg, params);
676
+ node.sFileToBePlayed = path.join(node.userDir, "ttsfiles", node.sFileToBePlayed);
677
+ if (!fs.existsSync(node.sFileToBePlayed)) {
678
678
  node.setNodeStatus({ fill: 'blue', shape: 'ring', text: 'Download using' + node.server.ttsservice });
679
679
  data = await synthesizeSpeechElevenLabs(node.server.elevenlabsTTS, params);
680
680
  } else {
@@ -685,10 +685,11 @@ module.exports = function (RED) {
685
685
  // Save the downloaded file into the cache
686
686
  if (data !== undefined) {
687
687
  try {
688
- fs.writeFileSync(sFileToBePlayed, data);
688
+ console.log("Salvelox " + node.sFileToBePlayed)
689
+ fs.writeFileSync(node.sFileToBePlayed, data);
689
690
  } catch (error) {
690
691
  RED.log.error("ttsultimate: node id: " + node.id + " Unable to save the file " + error.message);
691
- node.setNodeStatus({ fill: "red", shape: "ring", text: "Unable to save the file " + sFileToBePlayed + " " + error.message });
692
+ node.setNodeStatus({ fill: "red", shape: "ring", text: "Unable to save the file " + node.sFileToBePlayed + " " + error.message });
692
693
  throw (error);
693
694
  }
694
695
  }
@@ -696,12 +697,12 @@ module.exports = function (RED) {
696
697
  } catch (error) {
697
698
  RED.log.error("ttsultimate: node id: " + node.id + " Error Downloading TTS: " + error.message + ". THE TTS SERVICE MAY BE DOWN.");
698
699
  node.setNodeStatus({ fill: 'red', shape: 'ring', text: 'Error Downloading TTS:' + error.message });
699
- sFileToBePlayed = "";
700
+ node.sFileToBePlayed = "";
700
701
  }
701
702
  }
702
703
 
703
704
  // Ready to play
704
- if (sFileToBePlayed !== "") {
705
+ if (node.sFileToBePlayed !== "") {
705
706
 
706
707
  //#region Now i am ready to play the file
707
708
  if (node.playertype === "sonos") {
@@ -710,8 +711,8 @@ module.exports = function (RED) {
710
711
  node.setNodeStatus({ fill: 'green', shape: 'ring', text: 'Play ' + msg });
711
712
 
712
713
  // Play directly files starting with http://
713
- if (!sFileToBePlayed.toLowerCase().startsWith("http://") && !sFileToBePlayed.toLowerCase().startsWith("https://")) {
714
- sFileToBePlayed = node.sNoderedURL + "/tts/tts.mp3?f=" + encodeURIComponent(sFileToBePlayed);
714
+ if (!node.sFileToBePlayed.toLowerCase().startsWith("http://") && !node.sFileToBePlayed.toLowerCase().startsWith("https://")) {
715
+ node.sFileToBePlayed = node.sNoderedURL + "/tts/tts.mp3?f=" + encodeURIComponent(node.sFileToBePlayed);
715
716
  }
716
717
 
717
718
  // Set Volume
@@ -744,11 +745,11 @@ module.exports = function (RED) {
744
745
  };
745
746
 
746
747
  } catch (error) {
747
- RED.log.error("ttsultimate: Unable to set the volume for " + sFileToBePlayed);
748
+ RED.log.error("ttsultimate: Unable to set the volume for " + node.sFileToBePlayed);
748
749
  }
749
750
  try {
750
751
 
751
- await setAVTransportURISync(sFileToBePlayed);
752
+ await setAVTransportURISync(node.sFileToBePlayed);
752
753
 
753
754
  // Wait for start playing
754
755
  var state = "";
@@ -805,14 +806,14 @@ module.exports = function (RED) {
805
806
 
806
807
  } catch (error) {
807
808
  if (node.timerbTimeOutPlay !== null) clearTimeout(node.timerbTimeOutPlay); // Clear the player timeout
808
- RED.log.error("ttsultimate: Error HandleQueue for " + sFileToBePlayed + " " + error.message);
809
+ RED.log.error("ttsultimate: Error HandleQueue for " + node.sFileToBePlayed + " " + error.message);
809
810
  node.setNodeStatus({ fill: 'red', shape: 'dot', text: 'Error ' + msg + " " + error.message });
810
811
  }
811
812
 
812
813
  } else if (node.playertype === "noplayer") {
813
814
  // Output only the filename
814
815
  if (noPlayerFileArray === undefined || noPlayerFileArray === null) var noPlayerFileArray = [];
815
- noPlayerFileArray.push({ file: sFileToBePlayed });
816
+ noPlayerFileArray.push({ file: node.sFileToBePlayed });
816
817
  }
817
818
  }
818
819
  //#endregion