Så här gör man
Få igång nodejs på RPi
https://www.jeremymorgan.com/tutorials/ ... pberry-pi/
Få Google text till röst
http://elinux.org/RPi_Text_to_Speech_(Speech_Synthesis)
Här är skriptet jag kör på min RPi
Code: Select all
var net = require('net');
var cp = require('child_process');
/*
* Callback method executed when a new TCP socket is opened.
*/
function newSocket(socket) {
socket.write('Welcome to the Telnet server!');
socket.on('data', function(data) {
receiveData(socket, data);
})
}
/*
* Cleans the input of carriage return, newline
*/
function cleanInput(data) {
return data.toString().replace(/(\r\n|\n|\r)/gm,"");
}
/*
* Method executed when data is received from a socket
*/
function receiveData(socket, data)
{
var cleanData = cleanInput(data);
var speakCmd = '/usr/local/nodejs/speech.sh ';
var speakData = "";
switch(cleanData)
{
case "@frontdoor":
speakData = 'There is movement detected at the front door.';
break;
case "@sidehouse":
speakData = 'There is movement detected at the side of the house.';
break;
default:
speakData = cleanData;
}
cp.exec('/usr/local/nodejs/speech.sh + " " + speakData);
var currentTime = new Date()
var hours = currentTime.getHours()
var minutes = currentTime.getMinutes()
console.log(hours + ":" + minutes + " " + cleanData);
}
// Create a new server and provide a callback for when a connection occurs
var server = net.createServer(newSocket);
// Listen on port 5150
server.listen(5150);
cp.exec('/usr/local/nodejs/speech.sh Welcome.');
LUA kod på din HC2 som behövs
Code: Select all
tcpSocket = Net.FTcpSocket("192.168.0.237", 5150);
tcpSocket:setReadTimeout(1000);
tcpSocket:write("@frontdoor\r");
Att lägga till mer önskad text som du vill att din RPi ska säga så leta på raderna
Code: Select all
case "@frontdoor":
speakData = 'There is movement detected at the front door.';
break;
Lycka till