Commit 6aa2163b authored by Yoann HOUPERT's avatar Yoann HOUPERT
Browse files

add cheacker wav

parent f94813e8
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
*/ */
const app = require('express')(); const app = require('express')();
const fileUpload = require('express-fileupload');
const bodyParser = require('body-parser'); const bodyParser = require('body-parser');
const config = require('./config.json'); const config = require('./config.json');
...@@ -27,6 +28,7 @@ const routes = require('./lib/webserver/routes'); ...@@ -27,6 +28,7 @@ const routes = require('./lib/webserver/routes');
console.log('starting routes linstt-poc-socgen...'); console.log('starting routes linstt-poc-socgen...');
app.use(bodyParser.raw({type: 'audio/wav', limit: '200mb'})); app.use(bodyParser.raw({type: 'audio/wav', limit: '200mb'}));
app.use(fileUpload());
app.use('/', routes.routesFactory(config.orchestrator)); app.use('/', routes.routesFactory(config.orchestrator));
app.listen(config.api, () => { app.listen(config.api, () => {
console.log('App listening on port 3000'); console.log('App listening on port 3000');
......
{ {
"api": 3000, "api": 3000,
"orchestrator": { "orchestrator": {
"gstreamerURL": { "gstreamer": {
"url": "ws://localhost:3001/kaldi" "url": "http://172.20.0.2:80/client/dynamic/recognize",
"ws": "ws://hublot_kaldi-gstreamer_1:80/client/ws/speech?content-type=audio/x-matroska,+rate=(int)48000,+channels=(int)"
}, },
"speechEnhancement": { "speechEnhancement": {
"url" : "http://172.17.0.2:5000/upload", "url" : "http://172.17.0.2:5000/upload",
......
/*
* Copyright (c) 2017 Linagora.
*
* This file is part of linstt-poc-socgen
* (see https://ci.linagora.com/linagora/lgs/labs/linstt-poc-socgen).
*
* 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/>.
*/
const isFileValid = audio => {
console.log('control of the audio');
if(audio.mimetype !== 'audio/wave')
return false;
return true;
};
module.exports = {
isFileValid
};
...@@ -18,26 +18,30 @@ ...@@ -18,26 +18,30 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
const request = require('request'); const request = require('request');
const bodyParser = require('body-parser');
const fs = require('fs');
function enhancementlCallback(err, httpResponse, body) { function enhancementlCallback(err, httpResponse, body) {
if (err) { if (err) {
return console.error('upload failed:', err); return console.error('upload failed:', err);
} }
console.log('Upload successful!'); console.log('Upload successful!');
return body; return httpResponse;
} }
const enhancement = (wavFile, speechEnhancement) => { const enhancement = (wavFile, speechEnhancement) => {
const formData = { const formData = {
wavfile: wavFile, wavFile: wavFile.data,
msg: speechEnhancement.config msg: "-n"
}; };
// TODO until no docker-compose use debug mode // TODO until no docker-compose use debug mode
if (speechEnhancement.debug) { if (!speechEnhancement.debug) {
return request.post({url: speechEnhancement.url, form: formData}, enhancementlCallback); return request.post({url: speechEnhancement.url, form: formData}, enhancementlCallback);
}else {
return wavFile;
} }
return wavFile;
}; };
module.exports = { module.exports = {
......
...@@ -18,13 +18,24 @@ ...@@ -18,13 +18,24 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
const transcript = audio => { const request = require('request');
const enhancedAudio = audio;
console.log('Enhancement of the audio');
return enhancedAudio; function sttCallback(err, httpResponse, body) {
if (err) {
return console.error('upload failed:', err);
}
console.log('Transcript successful!');
return body;
}
const transcript = (audio, gstreamer) => {
const formData = {
audiofile: audio
};
// TODO until no docker-compose use debug mode
return request.post({url: gstreamer.url, form: formData}, sttCallback);
}; };
module.exports = { module.exports = {
transcript transcript
}; };
\ No newline at end of file
...@@ -21,21 +21,27 @@ ...@@ -21,21 +21,27 @@
const routesFactory = config => { const routesFactory = config => {
/* eslint new-cap: ["error", { "capIsNew": false }] */ /* eslint new-cap: ["error", { "capIsNew": false }] */
const routes = require('express').Router(); const routes = require('express').Router();
const enhancer = require('../speech-enhancement'); const enhancer = require('../speech-enhancement');
const stt = require('../speech-to-text'); const stt = require('../speech-to-text');
const control = require('../controller');
routes.post('/api/transcript', (req, res) => { let transcript = 'result';
// TODO manage first call to config.speechEnhancementURL
const wavEnhancement = enhancer.enhancement(req.body, config.speechEnhancement);
// TODO manage first call to config.gstreamerURL
stt.transcript(wavEnhancement);
res.status(200).json({message: 'transcript call'}); routes.post('/api/transcript', (req, res) => {
if (!req.files) {
return res.status(400).send('No files were uploaded.');
}
if (!control.isFileValid(req.files.wav)) {
return res.status(400).send('File is not valid.');
}
const wavEnhancement = enhancer.enhancement(req.files.wav, config.speechEnhancement);
//const transcriptRes = stt.transcript(wavEnhancement, config.gstreamer);
res.status(200).json({message: 'transcript call', transcript: wavEnhancement});
}); });
return routes; return routes;
}; };
module.exports = { module.exports = {
routesFactory routesFactory
}; };
\ No newline at end of file
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
"dependencies": { "dependencies": {
"body-parser": "^1.18.2", "body-parser": "^1.18.2",
"express": "^4.16.2", "express": "^4.16.2",
"express-fileupload": "^0.3.0",
"request": "^2.83.0" "request": "^2.83.0"
}, },
"devDependencies": { "devDependencies": {
......
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