Commit 2b2ea030 authored by Yoann HOUPERT's avatar Yoann HOUPERT

Merge branch 'frontend-initialisation' into 'master'

Frontend initialisation

See merge request !5
parents 8cf0a9e8 daff7bb6
Pipeline #9576 passed with stage
in 7 minutes and 13 seconds
......@@ -54,6 +54,9 @@ typings/
# Yarn Integrity file
.yarn-integrity
#HTTPS server certificat
ssl/*.pem
tmp/
nohup.out
models/
......@@ -19,7 +19,6 @@
*/
const https = require('https');
const fs = require('fs');
const app = require('express')();
const bodyParser = require('body-parser');
......@@ -28,7 +27,18 @@ const routes = require('./lib/webserver/routes');
console.log('starting routes linstt-controller...');
app.use(bodyParser.raw({type: 'audio/wav', limit: '200mb'}));
app.use(bodyParser.raw({type: 'audio/wave', limit: '200mb'}));
app.use(bodyParser.raw({type: 'audio/x-wav', limit: '200mb'}));
app.use(bodyParser.raw({type: 'audio/x-pn-wa', limit: '200mb'}));
app.use(bodyParser.raw({type: 'audio/vnd.wave', limit: '200mb'}));
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
next();
});
app.use('/', routes.routesFactory(config.orchestrator));
app.listen(config.api, () => {
......
......@@ -2,6 +2,7 @@
"api": 3000,
"apiSsl": 3001,
"orchestrator": {
"isOffline": false,
"gstreamer": {
"host": "linsttpoc_kaldi_1",
"host2": "linsttcontroller_kaldi_1",
......@@ -10,6 +11,13 @@
"recognize" : "client/dynamic/recognize"
}
},
"offline": {
"host": "linsttpoc_offline_1",
"port": "5000",
"api" : {
"upload" : "upload"
}
},
"speechEnhancement": {
"host": "linsttpoc_speech-enhencement_1",
"host2": "linsttcontroller_speech-enhencement_1",
......
......@@ -4,7 +4,13 @@ Create a transcript text from an audio file
**Request Headers:**
- Accept: application/json
Content-Type :
- audio/wav
- audio/wave
- audio/x-wav
- audio/x-pn-wa
- audio/vnd.wave
**Request Body**
......@@ -49,3 +55,4 @@ This endpoint expects the request body to be a wav file
{
status : X , err : 'here the error'
}
/*
* Copyright (c) 2017 Linagora.
*
* This file is part of linstt-controller
* (see https://ci.linagora.com/linagora/lgs/labs/linstt-controller).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
module.exports = config => {
const request = require('request');
const uuidv1 = require('uuid/v1');
return {
transcript: (wavFile, enhancementlCallback) => {
const url = 'http://' + config.host + ':' + config.port + '/' + config.api.upload;
const uiid = uuidv1();
let myUuidString = uiid.toString();
const re = /-/g;
myUuidString = re[Symbol.replace](myUuidString, '');
const options = {
url,
formData: {
wavFile: {
value: wavFile,
options: {
filename: myUuidString,
contentType: 'audio/x-wav'
}
}
},
encoding: null
};
request.post(options, enhancementlCallback);
return wavFile;
}
};
};
......@@ -23,6 +23,7 @@ const routesFactory = config => {
const routes = require('express').Router();
const enhancer = require('../controller/speech-enhancement')(config.speechEnhancement);
const stt = require('../controller/speech-to-text')(config.gstreamer);
const offline = require('../controller/offline')(config.offline);
routes.post('/api/transcript', (req, res) => {
if (!req.body) {
......@@ -34,22 +35,30 @@ const routesFactory = config => {
return res.status(500).send('Error while enhancing audio.' + err);
}
stt.transcript(body, (err, httpResponse, body) => {
if (err) {
return res.status(500).send('Error while transcript the audio.' + err);
} else if (body.indexOf('No workers available') !== -1) {
return res.status(500).send('No worker available for the moment.');
}
if (config.isOffline) {
offline.transcript(body, (err, httpResponse, body) => {
const json = JSON.parse(body);
if (json.status === 5) {
return res.status(500).send('Error while transcript the audio.');
}
return res.status(200).json({message: 'transcript done', hypotheses: json});
});
} else {
stt.transcript(body, (err, httpResponse, body) => {
if (err) {
return res.status(500).send('Error while transcript the audio.' + err);
} else if (body.indexOf('No workers available') !== -1) {
return res.status(500).send('No worker available for the moment.');
}
const json = JSON.parse(body);
if (json.status === 5) {
return res.status(500).send('Error while transcript the audio.');
}
return res.status(200).json({message: 'transcript done', transcript: json});
const json = JSON.parse(body);
if (json.status === 5) {
return res.status(500).send('Error while transcript the audio.');
}
return res.status(200).json({message: 'transcript done', transcript: json});
});
}
);
}
);
});
});
return routes;
};
......
......@@ -14,7 +14,8 @@
"body-parser": "^1.18.2",
"express": "^4.16.2",
"express-fileupload": "^0.3.0",
"request": "^2.83.0"
"request": "^2.83.0",
"uuid": "^3.1.0"
},
"devDependencies": {
"jest": "20.0.0",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment