node-red-contrib-sonospollytts
Advanced tools
Comparing version 1.1.38 to 1.1.39
@@ -6,3 +6,3 @@ ![Sample Node](img/logo.png) | ||
<p> | ||
<b>Version 1.1.38</b> December 2020<br/> | ||
<b>Version 1.1.39</b> December 2020<br/> | ||
- NEW: resume music queue after TTS speech. Once finished playing the voice speak, the music queue restart at the exact position, at the exact track time.<br/> | ||
@@ -9,0 +9,0 @@ - BUGFIX: fixing some issue when inbound msg to the node are very frequent. Should resume the music correctly.<br/> |
{ | ||
"name": "node-red-contrib-sonospollytts", | ||
"version": "1.1.38", | ||
"version": "1.1.39", | ||
"description": "Node-Red TTS with Sonos and Amazon Polly or with your own local mp3 announcement files. Transforms the text in speech and hear it using Sonos player. Can work OFFLINE as well! This node is specific for security alarm announcement, doorbell, weather annoucement etc.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -81,9 +81,6 @@ const { clear } = require('console'); | ||
node.sNoderedURL = ""; | ||
node.oTimerGetCurrentQueue = null; // 04/12/2020 | ||
node.oTimerResumeCurrentQueue = null; // 04/12/2020 | ||
node.currMusicTrack = null; // 04/12/2020 Current position of the currently playing music in the queue | ||
node.busyGettingMusicQueue = false; // 04/12/2020 Signal busy getting usic queue | ||
node.busyResumingMusicQueue = false; // 04/12/2020 Signal busy in resuming music queue | ||
node.tempMSGStorage = []; // 04/12/2020 Temporary stores the flow messages | ||
node.bResumeQueueAfterTTS = false; | ||
if (typeof node.server !== "undefined" && node.server !== null) { | ||
@@ -681,11 +678,2 @@ node.sNoderedURL = node.server.sNoderedURL || ""; | ||
// 04/12/2020 Start timer that read the music queue | ||
node.oTimerGetCurrentQueue = setInterval(function () { | ||
getMusicQueue().then(resolve => { | ||
}).catch(err => { | ||
}); | ||
}, 5000); | ||
// 27/11/2019 Start the connection healty check | ||
@@ -760,58 +748,58 @@ node.oTimerSonosConnectionCheck = setTimeout(function () { node.CheckSonosConnection(); }, 5000); | ||
// 04/12/2020 | ||
// If the queue management is still in process (starting or stopping the queue), store the input messages and send it upon end managing the queue | ||
if (node.busyGettingMusicQueue || node.busyResumingMusicQueue) { | ||
node.tempMSGStorage.push(msg.payload.toString()); | ||
if (node.busyGettingMusicQueue) node.setNodeStatus({ fill: 'grey', shape: 'dot', text: 'Busy in reading music queue...retry' }); | ||
if (node.busyResumingMusicQueue) node.setNodeStatus({ fill: 'grey', shape: 'dot', text: 'Busy in resuming music queue...retry' }); | ||
return; | ||
// Was playing music? | ||
if (node.aMessageQueue.length === 0) { | ||
getMusicQueue().then(ret => { | ||
node.bResumeQueueAfterTTS = ret; | ||
proceedWithmsg(); | ||
}).catch(err => { | ||
node.bResumeQueueAfterTTS = false; | ||
proceedWithmsg(); | ||
}); | ||
} | ||
function proceedWithmsg() { | ||
if (msg.hasOwnProperty("volume")) { | ||
node.sSonosVolume = msg.volume; | ||
} | ||
// Clear the read music queue timer | ||
if (node.oTimerGetCurrentQueue !== null) clearTimeout(node.oTimerGetCurrentQueue); | ||
node.busyGettingMusicQueue = false; // Resetting the glaf indicating busy in read music queue | ||
try { | ||
node.setNodeStatus({ | ||
fill: 'yellow', | ||
shape: 'dot', | ||
text: 'Processing ' + msg.payload | ||
}); | ||
} catch (error) { } | ||
// 12/06/2018 Controllo se il payload è un'impostazione del volume | ||
if (msg.hasOwnProperty("volume")) { | ||
node.sSonosVolume = msg.volume; | ||
} | ||
// 17/04/2019 Verifico se possso mandare in play l'hailing | ||
if (msg.hasOwnProperty("nohailing") && (msg.nohailing == "1" || msg.nohailing.toLowerCase() == "true")) { | ||
node.sonoshailing = "0"; | ||
} else { | ||
node.sonoshailing = config.sonoshailing; | ||
} | ||
try { | ||
node.setNodeStatus({ | ||
fill: 'yellow', | ||
shape: 'dot', | ||
text: 'Processing ' + msg.payload | ||
}); | ||
} catch (error) { } | ||
// 17/04/2019 Verifico se possso mandare in play l'hailing | ||
if (msg.hasOwnProperty("nohailing") && (msg.nohailing == "1" || msg.nohailing.toLowerCase() == "true")) { | ||
node.sonoshailing = "0"; | ||
} else { | ||
node.sonoshailing = config.sonoshailing; | ||
} | ||
// 09/03/2020 Change hailing | ||
if (msg.hasOwnProperty("sonoshailing")) node.sonoshailing = "Hailing_" + msg.sonoshailing + ".mp3"; | ||
// 09/03/2020 Change hailing | ||
if (msg.hasOwnProperty("sonoshailing")) node.sonoshailing = "Hailing_" + msg.sonoshailing + ".mp3"; | ||
// 07/05/2019 Set "completed" to false and send it | ||
if (node.aMessageQueue.length == 0) { | ||
node.msg.completed = false; | ||
node.groupSpeakers(); // 20/03/2020 Group Speakers toghether | ||
node.send(node.msg); | ||
} | ||
// 07/05/2019 Set "completed" to false and send it | ||
if (node.aMessageQueue.length == 0) { | ||
node.msg.completed = false; | ||
node.groupSpeakers(); // 20/03/2020 Group Speakers toghether | ||
node.send(node.msg); | ||
// If the queue is empty and if i can play the Haniling, add the hailing file first | ||
if (node.aMessageQueue.length == 0 && node.sonoshailing !== "0") { | ||
node.aMessageQueue.push(node.sonoshailing); | ||
node.setNodeStatus({ fill: 'yellow', shape: 'dot', text: 'Queued Hail' }); | ||
} | ||
// 26/10/2020 Add the message to the array, as string, otherwise it doe'snt work | ||
node.aMessageQueue.push(msg.payload.toString()); | ||
node.setNodeStatus({ fill: 'yellow', shape: 'dot', text: 'Queued ' + msg.payload }); | ||
} | ||
// If the queue is empty and if i can play the Haniling, add the hailing file first | ||
if (node.aMessageQueue.length == 0 && node.sonoshailing !== "0") { | ||
node.aMessageQueue.push(node.sonoshailing); | ||
node.setNodeStatus({ fill: 'yellow', shape: 'dot', text: 'Queued Hail' }); | ||
} | ||
// 26/10/2020 Add the message to the array, as string, otherwise it doe'snt work | ||
node.aMessageQueue.push(msg.payload.toString()); | ||
node.setNodeStatus({ fill: 'yellow', shape: 'dot', text: 'Queued ' + msg.payload }); | ||
}); | ||
@@ -840,38 +828,11 @@ | ||
return new Promise(function (resolve, reject) { | ||
// 04/12/2020 Get music queue | ||
if (!node.msg.completed) { | ||
resolve(true); | ||
return; // Is playing TTS, exit. | ||
} | ||
node.busyGettingMusicQueue = true; // Avoid enterint here while the promises below are not resolved | ||
node.SonosClient.getCurrentState().then(state => { | ||
// A music queue is playing and no TTS is speaking? | ||
if (state.toString().toLowerCase() === "playing") { | ||
if (!node.msg.completed) { | ||
// Is playing TTS, exit. | ||
node.currMusicTrack = null; | ||
node.busyGettingMusicQueue = false; // Avoid enterint here while the promises below are not resolved | ||
reject(true); | ||
return; | ||
} | ||
if (state.toString().toLowerCase() === "playing" && node.msg.completed) { | ||
// Get current track | ||
node.SonosClient.currentTrack().then(track => { | ||
if (!node.msg.completed) { | ||
// Is playing TTS, exit. | ||
node.currMusicTrack = null; | ||
node.busyGettingMusicQueue = false; // Avoid enterint here while the promises below are not resolved | ||
reject(true); | ||
return; | ||
} | ||
node.currMusicTrack = track;// .queuePosition || 1; // Get the current track in the queue. | ||
node.SonosClient.getVolume().then(volume => { | ||
if (!node.msg.completed) { | ||
// Is playing TTS, exit. | ||
node.currMusicTrack = null; | ||
node.busyGettingMusicQueue = false; // Avoid enterint here while the promises below are not resolved | ||
reject(true); | ||
return; | ||
} | ||
node.currMusicTrack.currentVolume = volume; // Get the current volume | ||
node.busyGettingMusicQueue = false; // finish handling music queue | ||
//console.log("TRACK MUSIC: " + JSON.stringify(node.currMusicTrack)); | ||
@@ -882,3 +843,2 @@ node.setNodeStatus({ fill: 'grey', shape: 'dot', text: 'Playing music queue pos: ' + node.currMusicTrack.queuePosition }); | ||
node.currMusicTrack = null; | ||
node.busyGettingMusicQueue = false; // finish handling music queue | ||
//console.log('SonospollyTTS: getVolume Error occurred %j', err); | ||
@@ -889,3 +849,2 @@ reject(err); | ||
node.currMusicTrack = null; | ||
node.busyGettingMusicQueue = false; // finish handling music queue | ||
reject(err); | ||
@@ -896,8 +855,6 @@ //console.log('SonospollyTTS: Error currentTrackoccurred %j', err); | ||
node.currMusicTrack = null; // Avoid play last queue at end of the tts speech | ||
node.busyGettingMusicQueue = false; // finish handling music queue | ||
resolve(true); | ||
resolve(false); | ||
}; | ||
}).catch(err => { | ||
//console.log('SonospollyTTS: getCurrentState: Error occurred %j', err); | ||
node.busyGettingMusicQueue = false; // finish handling music queue | ||
reject(err); | ||
@@ -919,7 +876,5 @@ }) | ||
node.SonosClient.play().then(success => { | ||
node.busyResumingMusicQueue = false; | ||
resolve(true); | ||
}).catch(err => { | ||
//console.log('Error occurred PLAY %j', err) | ||
node.busyResumingMusicQueue = false; | ||
reject(Err); | ||
@@ -929,3 +884,2 @@ }) | ||
//console.log('Error occurred setVolume %j', err) | ||
snode.busyResumingMusicQueue = false; | ||
reject(Err); | ||
@@ -935,3 +889,2 @@ }) | ||
//console.log('Error occurred SEEK %j', err) | ||
node.busyResumingMusicQueue = false; | ||
reject(Err); | ||
@@ -941,3 +894,2 @@ }) | ||
//console.log('Error occurred SELECTTRACK %j', err); | ||
node.busyResumingMusicQueue = false; | ||
reject(Err); | ||
@@ -948,8 +900,6 @@ }) | ||
//console.log('Error occurred %j', err); | ||
node.busyResumingMusicQueue = false; | ||
reject(Err); | ||
}) | ||
} else { | ||
node.busyResumingMusicQueue = false; // 04/12/2020 Signal end in resuming queue | ||
resolve(true); | ||
resolve(false); | ||
} | ||
@@ -1137,32 +1087,4 @@ | ||
if (node.msg.completed === false && node.sSonosPlayState == "stopped") { | ||
if (node.currMusicTrack === null) { | ||
node.ungroupSpeakers(); // 20/03/2020 Ungroup Speakers | ||
node.msg.completed = true; | ||
node.send(node.msg); | ||
node.setNodeStatus({ fill: "green", shape: "ring", text: "Done." }); | ||
return; | ||
} | ||
//console.log("PANAMA PANAMA PANAMA PANAMA PANAMA PANAMA " + node.busyGettingMusicQueue + " " + node.busyResumingMusicQueue) | ||
if (node.busyGettingMusicQueue || node.busyResumingMusicQueue) { | ||
if (node.oTimerResumeCurrentQueue !== null) clearTimeout(node.oTimerResumeCurrentQueue); | ||
node.oTimerResumeCurrentQueue = setTimeou(() => { | ||
resumeMusicQueue().then(success => { | ||
if (node.oTimerResumeCurrentQueue !== null) clearInterval(node.oTimerResumeCurrentQueue); | ||
node.msg.completed = true; | ||
node.send(node.msg); | ||
node.setNodeStatus({ fill: "green", shape: "ring", text: "Done." }); | ||
}).catch(err => { | ||
if (node.oTimerResumeCurrentQueue !== null) clearInterval(node.oTimerResumeCurrentQueue); | ||
node.msg.completed = true; | ||
node.send(node.msg); | ||
node.busyResumingMusicQueue = false; | ||
node.busyGettingMusicQueue = false; | ||
node.setNodeStatus({ fill: "green", shape: "ring", text: "Done." }); | ||
}); | ||
}, 3000) | ||
} else { | ||
if (node.oTimerResumeCurrentQueue !== null) clearTimeout(node.oTimerResumeCurrentQueue); | ||
if (node.bResumeQueueAfterTTS) { | ||
// Resume Queue | ||
resumeMusicQueue().then(success => { | ||
@@ -1177,12 +1099,15 @@ node.msg.completed = true; | ||
node.busyResumingMusicQueue = false; | ||
node.busyGettingMusicQueue = false; | ||
node.setNodeStatus({ fill: "green", shape: "ring", text: "Error resuming queue." }); | ||
}); | ||
} else { | ||
// I don't need to resume the queue | ||
node.ungroupSpeakers(); // 20/03/2020 Ungroup Speakers | ||
node.msg.completed = true; | ||
node.send(node.msg); | ||
node.setNodeStatus({ fill: "green", shape: "ring", text: "Done." }); | ||
return; | ||
} | ||
} | ||
} catch (error) { | ||
@@ -1192,5 +1117,2 @@ | ||
// Resume Queue | ||
} | ||
@@ -1197,0 +1119,0 @@ } |
861890
1522