forked from aadishjain1946/AssistME
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
71 lines (67 loc) · 2.34 KB
/
index.js
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
59
60
61
62
63
64
65
66
67
68
69
70
71
const say = require('say');
const express = require('express');
const socket = require("socket.io");
const fs = require('fs');
const path = require('path');
const bodyParser = require('body-parser');
const app = express();
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json({ extended: true, limit: '50mb' }));
app.use(express.static('public'))
function pythonloadfacerec() {
console.log("sdfjhgs")
let { PythonShell } = require('python-shell')
let pyshell = new PythonShell(path.join(__dirname, "face_rec/") + 'script.py');
pyshell.on('message', function (message) {
say.speak(message);
});
pyshell.end(function (err, code, signal) {
if (err) throw err;
console.log('finished');
});
}
app.post('/sendimg', (req, res) => {
// console.log(req.body)
data = req.body.data.rawdata.replace(/^data:image\/png;base64,/, "");
type = req.body.data.type;
if (type == 'ocr') {
fs.writeFile(path.join(__dirname, "face_rec/") + "/images/out.png", data, 'base64', function (err) {
if (!err) {
var ocrdata = "";
const Tesseract = require('tesseract.js');
Tesseract.create({ langpath: "eng.traineddata" }).recognize("D:/Disk storage 2/Aadish jain/web designing/text-to-speech/face_rec/Images/out.png", 'eng')
.then(function (result) {
dt = result.text;
ocrdata = dt;
console.log("@#@#@#@#", ocrdata)
say.speak(ocrdata)
})
}
});
}
else if (type == 'fr') {
fs.writeFile(path.join(__dirname, "face_rec/") + "/images/out.png", data, 'base64', function (err) {
if (!err) {
pythonloadfacerec();
}
});
}
})
// say.export("sfsadf", 'Cellos', 0.75, 'public/new_file.wav', (err) => {
// if (!err) {
// console.log("file saved");
// }
// });
const server = app.listen(1234, (err) => {
if (!err) {
console.log("server");
}
})
var io = socket(server);
io.sockets.on('connection', function (socket) {
fs.watchFile(fullPath, () => {
var content = fs.readFileSync(fullPath);
console.log('File Content is ' + content);
socket.emit('new_audio', { data: content });
});
});