Commit f86cb660 authored by Yoann HOUPERT's avatar Yoann HOUPERT

allow to use offline transcrib

parent 0e2091bf
Pipeline #9401 failed with stage
in 26 seconds
......@@ -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",
......
/*
* 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();
let 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,31 @@ 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});
});
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});
} 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});
});
}
);
}
);
});
});
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