Created
June 28, 2017 11:30
-
-
Save marcotchella/fcdf9920015fd90b156f7f835cd28ae3 to your computer and use it in GitHub Desktop.
adaptação do servidor NodeJS do SDK IBM Watson Speech Services for Web Browsers para controle de um robô móvel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
/* eslint-env node, es6 */ | |
const express = require('express'); | |
const app = express(); | |
var request = require('request'); | |
const sleep = require('system-sleep'); | |
app.use(express.static(__dirname + '/static')); | |
// token endpoints | |
// **Warning**: these endpoints should probably be guarded with additional authentication & authorization for production use | |
app.use('/api/speech-to-text/', require('./stt-token.js')); | |
app.use('/api/text-to-speech/', require('./tts-token.js')); | |
const port = process.env.PORT || process.env.VCAP_APP_PORT || 3000; | |
app.listen(port, function() { | |
console.log('Example IBM Watson Speech JS SDK client app & token server live at http://localhost:%s/', port); | |
}); | |
// enviar comandos para o robo Ori | |
app.get('/msg/:comando', function(req, res) { | |
console.log("recebeu do cliente") | |
var comando_recebido = req.params.comando; | |
if (comando_recebido.indexOf("fre") >= 0) | |
{ | |
request('http://192.168.0.20/msg=fre', function (error, response, body) { | |
console.log('error:', error); | |
console.log('statusCode:', response && response.statusCode); | |
console.log('body:', body); | |
}); | |
res.send("recebeu"); | |
sleep(300); | |
request('http://192.168.0.20/msg=par', function (error, response, body) { | |
console.log('error:', error); | |
console.log('statusCode:', response && response.statusCode); | |
console.log('body:', body); | |
}); | |
res.send("recebeu"); | |
} | |
else | |
{ | |
request('http://192.168.0.20/msg='+comando_recebido, function (error, response, body) { | |
console.log('error:', error); | |
console.log('statusCode:', response && response.statusCode); | |
console.log('body:', body); | |
}); | |
res.send("recebeu"); | |
} | |
}); | |
// chrome requires https to access the user's microphone unless it's a localhost url so | |
// this sets up a basic server at https://localhost3001/ using an included self-signed certificate | |
// note: this is not suitable for production use | |
// however bluemix automatically adds https support at http://<myapp>.mybluemix.net | |
const fs = require('fs'); | |
const https = require('https'); | |
const HTTPS_PORT = 3001; | |
const options = { | |
key: fs.readFileSync(__dirname + '/keys/localhost.pem'), | |
cert: fs.readFileSync(__dirname + '/keys/localhost.cert') | |
}; | |
https.createServer(options, app).listen(HTTPS_PORT, function() { | |
console.log('Secure server live at https://localhost:%s/', HTTPS_PORT); | |
}); | |
//=========================================================================================== | |
//Para vídeo explicativo e referência visite o blog FazerLab: | |
//https://fazerlab.wordpress.com/2017/06/28/como-criar-um-robo-com-cerebro-de-supercomputador/ | |
//Nas redes sociais: | |
//https://twitter.com/@chellamarco | |
//Facebook: https://goo.gl/45PEq2 | |
// 28/06/2017 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment