Repository navigation
Expand file tree
/
Copy pathnode_helper.js
More file actions
executable file
·58 lines (51 loc) · 1.57 KB
/
Copy pathnode_helper.js
File metadata and controls
executable file
·58 lines (51 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
'use strict';
const NodeHelper = require('node_helper');
const {PythonShell} = require('python-shell');
var pythonStarted = false;
module.exports = NodeHelper.create({
python_start: function () {
const self = this;
self.pyshell = new PythonShell('modules/' + this.name + '/pythonscripts/stringToTTS.py', { pythonPath: 'python', args: [JSON.stringify(this.config)]});
self.pyshell.on('message', function (message) {
try{
var parsed_message = JSON.parse(message)
//console.log("[MSG " + self.name + "] " + message);
if (parsed_message.hasOwnProperty('status')){
console.log("[" + self.name + "] " + parsed_message.status);
}
}
catch(err) {
//console.log(err)
}
});
},
// Subclass socketNotificationReceived received.
socketNotificationReceived: function(notification, payload) {
const self = this;
if(notification === 'TTS-en') {
if(pythonStarted) {
var data = {"en": payload}
self.pyshell.send(JSON.stringify(data));
}
}else if(notification === 'TTS-ger') {
if(pythonStarted) {
var data = {"ger": payload}
self.pyshell.send(JSON.stringify(data));
}
}else if(notification === 'CONFIG') {
console.log("[" + self.name + "] starting");
this.python_start();
pythonStarted = true;
};;
},
stop: function() {
const self = this;
self.pyshell.childProcess.kill('SIGKILL');
self.pyshell.end(function (err) {
if (err){
//throw err;
};
console.log('finished');
});
}
});