Skip to content

Instantly share code, notes, and snippets.

@PonDad
Created June 11, 2017 09:19
Show Gist options
  • Save PonDad/8bee4453c2bdf375ebf72975a3c7376a to your computer and use it in GitHub Desktop.
Save PonDad/8bee4453c2bdf375ebf72975a3c7376a to your computer and use it in GitHub Desktop.
Samuel L Jackson's face recognition with Google Assistant & Raspberry Pi
'use strict';
process.env.DEBUG = 'actions-on-google:*';
const App = require('actions-on-google').ApiAiApp;
const exec = require('child_process').exec;
const camera_adress = "https://7bdaf661.ap.ngrok.io/camera"
const what_adress = "https://7bdaf661.ap.ngrok.io/what"
const face_adress = "https://7bdaf661.ap.ngrok.io/face"
const who_adress = "https://7bdaf661.ap.ngrok.io/who"
// [START YourAction]
exports.myAction = (request, response) => {
const app = new App({request, response});
console.log('Request headers: ' + JSON.stringify(request.headers));
console.log('Request body: ' + JSON.stringify(request.body));
function responseCamera (app) {
exec(`curl ${camera_adress}`, (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
return;
}
console.log(`${stdout}`);
app.ask(`<speak>I took <break time='1' /></speak>` + `${stdout}`);
});
}
function responseWhat (app) {
exec(`curl ${what_adress}`, (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
return;
}
console.log(`${stdout}`);
app.ask(`<speak>This is a <break time='1' /></speak>` + `${stdout}`);
});
}
function responseCorrect (app) {
app.ask(`<speak>Thank you.</speak>`);
}
function responseFace (app) {
exec(`curl ${face_adress}`, (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
return;
}
console.log(`${stdout}`);
app.ask(`<speak>I took <break time='1' /></speak>` + `${stdout}`);
});
}
function responseWho (app) {
exec(`curl ${who_adress}`, (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
return;
}
console.log(`${stdout}`);
if(`${stdout}` === 'Samuel'){
app.ask(`<speak>Hello <break time='1' /></speak>` + `${stdout}` + `<speak>!<break time='1' /> Do you know what they call a Quarter Pounder with Cheese in Paris?</speak>`);
} else{
app.ask(`<speak>Hello <break time='1' /></speak>` + `${stdout}` + `<speak>!</speak>`);
}
});
}
function responseCall (app) {
app.ask(`<speak>They call it Royale with Cheese.
</speak>`);
}
const actionMap = new Map();
actionMap.set('talk.camera', responseCamera);
actionMap.set('talk.what', responseWhat);
actionMap.set('talk.correct', responseCorrect);
actionMap.set('talk.face', responseFace);
actionMap.set('talk.who', responseWho);
actionMap.set('talk.call', responseCall);
app.handleRequest(actionMap);
};
// [END YourAction]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment