Samreen, Thank you for your help.
Yes indeed, my script does something similar. It consists of 3 parts:
- setup for mqtt and tts
- wakeword identification and voice response
- several scripts to trigger different devices, example: temperature with announcement of the requested value
// Script to send Voice via TTS to Rhasspy
// Rhasspy-TTS setup:
let http = require(‘http’);
let options = {
host: ‘192.168.xxx.yyy’, //Rhasspy IP-Adresse
port: 12101, //Rhasspy Port
path: “/api/text-to-speech”,
method: ‘POST’,
headers: {
‘User-Agent’ : ‘ioBroker’,
‘Content-Type’: ‘text/plain’,
// ‘Content-Length’: data.length
}
};
function httpPost(data) {
let req = http.request(options, function(res) {
console.log("http Status: " + res.statusCode);
console.log('HEADERS: ' + JSON.stringify(res.headers), (res.statusCode != 200 ? "warn" : "info"));
});
// on error
req.on('error', function(e) {
console.log('ERROR: ' + e.message,"warn");
});
// write data to request body
console.log("Data to request body: " + data);
(data ? req.write(data) : console.log("Daten: keine Daten vorhanden"));
req.end();
}
//______________________________________________________________________________
//Script to respond on WakeWord
const wake = ‘mqtt.0.rhasspy.de.transition.SnowboyWakeListener’ // Datenpunkt aendert sich von listening auf loaded, wenn wakeword erkannt wurde
const befehl = ‘mqtt.0.rhasspy.de.transition.WebrtcvadCommandListener’ // Datenpunkt aendert sich von listening auf loaded, wenn befehl erkannt erkannt wurde
const ansage = ‘Yeah?’ // in case wakeword was recognised
const empf_ok = “OK” // in case command was recognised
on({id: wake, change: “any”},function(obj) {
let empf_code = getState(wake).val ;
if (empf_code== “loaded”){ wakeword(); }
});
on({id: befehl, change: “any”},function(obj) {
let empf_code = getState(befehl).val ;
if (empf_code== “loaded”){ befehl_empf(); }
});
function wakeword(){
httpPost(ansage);
}
function befehl_empf(){
httpPost(empf_ok);
}
//______________________________________________________________________________
//script to ask for temperatures
var intentResult = $(‘mqtt.0.rhasspy.intent.*Temperature’);
var intentArray = [];
for(var i = 0; i < intentResult.length; i++)
{
log(intentResult[i]);
intentArray.push(intentResult[i]);
}
on({id: intentArray, change: “any”}, function (obj) {
log(obj.newState.val);
let intentObject = JSON.parse(obj.newState.val);
if(intentObject.hasOwnProperty(‘device’))
{
var deviceID = intentObject.device;
var state = intentObject.state;
var value = getState(deviceID + state);
let data = 'It's currently ' + value.val + ' degrees Celsius';
console.log("data: " + data);
httpPost(data);
}
});
I’ll be waiting patiently for your answer.
best regards
Thomas