Commit ab596494 authored by Yoann HOUPERT's avatar Yoann HOUPERT
Browse files

clean code resume

parent a6f45e00
Pipeline #12701 canceled with stage
......@@ -28,6 +28,8 @@ const controllerFactory = require('./lib/controller.js');
const proxy = require('./lib/proxy.js')(config.proxy);
const resumeGenerator = require('./lib/resume.js')(config.offline)
console.log('starting hublot...');
loader.loadAll('controller', 'lib', 'robot')
......@@ -43,7 +45,7 @@ loader.loadAll('controller', 'lib', 'robot')
console.log('App listening on port 3000');
});
proxy.create();
proxy.create(resumeGenerator);
})
.catch(err => {
console.error(err);
......
......@@ -47,5 +47,18 @@
},
"kaldi": "ws://hublot_kaldi-gstreamer_1:80/client/ws/speech?content-type=audio/x-matroska,+rate=(int)48000,+channels=(int)"
}
},
"offline": {
"folder": {
"audioRaw": "audio_raw",
"audio": "audio_wav"
},
"audio":{
"format": "wav",
"bitrate": "16k",
"channels": 1
},
"host": "hublot_offline_1",
"port": 9999
}
}
......@@ -18,9 +18,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
const fs = require('fs');
const http = require('http');
const uuidv1 = require('uuid/v1');
const SockJS = require('sockjs-client');
const stomp = require('webstomp-client');
const WebSocket = require('ws');
......@@ -56,20 +54,16 @@ module.exports = config => {
return stompCapsule;
}
function kaldiWS(connectionToClient) {
if (!fs.existsSync('hublot_audio')) {
fs.mkdirSync('hublot_audio');
}
function kaldiWS(connectionToClient, resume) {
const connectionToKaldi = new WebSocket(config.services.kaldi);
connectionToKaldi.on('open', () => {
const filename = uuidv1();
const wstream = fs.createWriteStream('hublot_audio/' + filename + '.wav');
const streamData = resume.generateStream();
connectionToClient.on('message', message => {
connectionToKaldi.send(message, {
binary: true
});
wstream.write(message);
streamData.wstream.write(message);
});
connectionToKaldi.on('message', message => {
......@@ -82,7 +76,10 @@ module.exports = config => {
});
connectionToClient.on('close', () => connectionToKaldi.close());
connectionToKaldi.on('close', () => connectionToClient.close());
connectionToKaldi.on('close', () => {
resume.endStream(streamData)
connectionToClient.close()
});
});
}
......@@ -148,7 +145,9 @@ module.exports = config => {
}
return {
create: () => {
create: (resume) => {
resume.createFolder()
const server = http.createServer();
const stompClient = createStompClient();
......@@ -160,7 +159,7 @@ module.exports = config => {
wssServer.on('connection', (connectionToClient, req) => {
if (req.url === '/kaldi') {
kaldiWS(connectionToClient);
kaldiWS(connectionToClient, resume);
return;
}
if (req.url === '/chat') {
......
/*
* Copyright (c) 2017 Linagora.
*
* This file is part of Hublot
* (see https://ci.linagora.com/linagora/lgs/labs/hublot).
*
* 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 fs = require('fs');
const uuidv1 = require('uuid/v1');
const ffmpegInstaller = require('@ffmpeg-installer/ffmpeg');
const ffmpeg = require('fluent-ffmpeg');
ffmpeg.setFfmpegPath(ffmpegInstaller.path);
module.exports = ffmpeg;
module.exports = config => {
let timestamp = undefined;
return {
createFolder : () => {
if (!fs.existsSync(config.folder.audioRaw)) {
fs.mkdirSync(config.folder.audioRaw);
}
if (!fs.existsSync(config.folder.audio)) {
fs.mkdirSync(config.folder.audio);
}
},
generateStream : () => {
if(timestamp === undefined){
timestamp = new Date().getTime()
}
const name = uuidv1()
const path = config.folder.audioRaw+"/"+name+".wav"
const streamData = {
"wstream" : fs.createWriteStream(path),
"pathFile" : path,
"fileName": name,
"timestamp" : new Date().getTime()
}
return streamData
},
endStream : (streamData) => {
streamData.wstream.close();
let delay = timestamp - streamData.timestamp;
console.log(delay)
console.log(streamData.pathFile)
try{
ffmpeg(streamData.pathFile)
.toFormat(config.audio.format)
.noVideo()
.audioBitrate(config.audio.bitrate)
.audioChannels(config.audio.channels)
.save(config.folder.audio+"/"+streamData.fileName+".wav")
/*.on('end', function(stdout, stderr) {
console.log('File generated ended succeeded !');
});*/
} catch(err){
// Sometimes, the client will close the connection unexpectedly
// (e.g. when stopping). This is expected
}
}
};
};
......@@ -13,9 +13,11 @@
"webdriver-stop": "./bin/webdriver-stop"
},
"dependencies": {
"@ffmpeg-installer/ffmpeg": "^1.0.13",
"body-parser": "^1.18.2",
"express": "^4.16.2",
"file-system": "^2.2.2",
"fluent-ffmpeg": "^2.1.2",
"mz": "2.6.0",
"puppeteer": "0.12.0",
"sockjs-client": "1.1.4",
......
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