i8beef / node-red-contrib-castv2

MIT License
22 stars 14 forks source link

dynamic value in TTS-Call #45

Closed Einstein2150 closed 3 years ago

Einstein2150 commented 3 years ago

Not really a problem of the node but I think you can help me very quick. Im sending something like

return { payload: { app: "DefaultMediaReceiver", type: "TTS", text: "Guten Morgen!", speed: 1, // optional to adjust TTS speed, defaults to 1 language: "de", // optional to set TTS language, default to en metadata: { // optional unless desired, follows normal metadata rules noted above title: "Media title" } } };

and it works very well. How can I append an additional value from another node to the text? For example I have a actual temperature value in a message msg.payload.CurrentTemperature. Now I want to append to the Text "Today we have xx degrees outside." 🤔

Wrapping it like

return {` payload: { app: "DefaultMediaReceiver", type: "TTS", text: "Guten Morgen! Draußen sind es ${msg.payload.CurrentTemperature} Grad.", speed: 1, // optional to adjust TTS speed, defaults to 1 language: "de", // optional to set TTS language, default to en metadata: { // optional unless desired, follows normal metadata rules noted above title: "Media title" } } `};

returns a "Funktion hat versucht, eine Nachricht vom Typ string zu senden" (the function tried to send a message of the type string)...

Einstein2150 commented 3 years ago

I got it. I have to backtick only the part after "text": msg = { payload: { app: "DefaultMediaReceiver", type: "TTS", text: `"Guten Morgen! Draußen sind es ${msg.payload.CurrentTemperature} Grad."`, speed: 1, // optional to adjust TTS speed, defaults to 1 language: "de", // optional to set TTS language, default to en metadata: { // optional unless desired, follows normal metadata rules noted above title: "Media title" } } }; return msg;