Commit 7af2ed92 authored by Yoann HOUPERT's avatar Yoann HOUPERT

add offline

parent 74db6c7e
Pipeline #14279 failed with stage
......@@ -29,8 +29,11 @@ const controllerFactory = require('./lib/controller.js');
const proxy = require('./lib/proxy.js')(config.proxy);
const resumeGenerator = require('./lib/resume.js')(config.offline, config.resume)
require('dotenv').config()
require('dotenv').config(config.debug)
process.env.ASD_CONTROL_PORT = config.proxy.asd.asd_control_port
process.env.ASD_STREAM_PORT = config.proxy.asd.asd_stream_port
process.env.ASD_SERVER_IP = config.proxy.asd.asd_server_ip
console.log('starting hublot...');
......@@ -46,7 +49,6 @@ loader.loadAll('controller', 'lib', 'robot')
app.listen(config.api, () => {
console.log('App listening on port 3000');
});
proxy.create(resumeGenerator);
})
.catch(err => {
......
......@@ -123,11 +123,6 @@ robot = {
},
clearConnection() {
for (let i = 0; i < robot.intervalList.length; i++) {
clearInterval(robot.intervalList[i]);
}
robot.intervalList = [];
for (let i = 0; i < robot.recordedParticipantsWS.length; i++) {
try {
robot.stopRecordParticipant(robot.recordedParticipantsWS[i]);
......@@ -135,6 +130,12 @@ robot = {
console.log('This user is inactive');
}
}
for (let i = 0; i < robot.intervalList.length; i++) {
clearInterval(robot.intervalList[i]);
}
robot.intervalList = [];
robot.recordedParticipantsWS = [];
},
......@@ -227,8 +228,8 @@ robot = {
stop: () => {
robot.isDisconnected = true;
robotController.disconnect();
robot.clearConnection();
robotController.disconnect();
// This function is set by the server
/* eslint-disable no-undef */
......
{
"debug":"lib:*",
"visio": {
"url": "http://janus.hubl.in"
},
......@@ -39,17 +40,21 @@
},
"api": 3000,
"proxy": {
"asd": false,
"port_ws_audio": 3001,
"port_server_proxy": 3002,
"services": {
"reco": {
"host": "83.212.204.91",
"host_docker": "hublot_recommender_1",
"host": "hublot_recommender_1",
"port": 8080,
"reconnectInterval": 5000
},
"kaldi": "ws://hublot_kaldi-gstreamer_1:80/client/ws/speech?content-type=audio/x-matroska,+rate=(int)48000,+channels=(int)"
},
"asd" :{
"used": false,
"asd_server_ip": "10.31.4.100",
"asd_control_port": 8881,
"asd_stream_port": 8882
}
},
"offline": {
......@@ -75,6 +80,7 @@
"host": "83.212.204.91",
"hostName": "datascience.open-paas.org",
"port": 80,
"isUse" : true,
"api": "abs_summ/api",
"query": "&enc=utf-8&nkeys=100&lang=fr",
"resumeFolder": "resume"
......
//start a netcat socket mirror
// ncat --broker --listen -p PORT_NUMBER : dispatch anydata to all
// nc -l -p PORT_NUMBER
process.env.ASD_CONTROL_PORT = 8881
process.env.ASD_STREAM_PORT = 8882
process.env.ASD_SERVER_IP = "localhost"
const debug = require('debug')('lib:asd')
const {
EventEmitter
......@@ -22,7 +18,7 @@ class Asd extends EventEmitter {
try {
this.streams = []
await this.controlConnect()
resolve()
resolve(this)
} catch (e) {
//eventual catch of explicit rejections in awaited function
reject(e)
......
......@@ -25,8 +25,6 @@ const WebSocket = require('ws');
const XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest;
const fs = require('fs');
const Asd = require('./asd');
module.exports = config => {
function createStompClient() {
const stompCapsule = {
......@@ -145,39 +143,45 @@ module.exports = config => {
transports: ['websocket']
});
io.sockets.on('connection', (socket) => {
let asd = Asd //port 8881 - connexion de contrôle ASD
io.sockets.on('connection', async (socket) => {
let asd;
if (config.asd.used) {
asd = await require('./asd')
}
let userAudioEvents = []
socket.on('error', (err) => {
for (userEvent in userAudioEvents) {
socket.removeListener(userEvent)
}
userAudioEvents = []
asd = {} //disconnect and kill asd sockets
})
socket.on('new_user', (userId) => {
socket.on('new_user', async (userId) => {
const streamData = resume.generateStream()
let transcriptor
let thisUserStream;
if (!config.asd)
if (config.asd.used) {
transcriptor = await asd.streamConnect()
} else {
transcriptor = kaldiWS(userId, socket)
else {
transcriptor = asd
thisUserStream = transcriptor.streamConnect()
}
//create ASD stream //port 8882 - connexion de data
userAudioEvents.push('audio_from_' + userId)
//asd.on("resume_data", soket.emit('resume_data'))
//register custom event for user
socket.on('audio_from_' + userId, (data) => {
if (!config.asd) {
transcriptor.send(data, {
binary: true
});
if (config.asd.used) {
asd.streamPush(transcriptor, data) //asd
} else {
transcriptor.streamPush(thisUserStream, data)
if (transcriptor.readyState === 2 || transcriptor.readyState === 3) {
transcriptor = kaldiWS(userId, socket)
}
if (transcriptor.readyState === 1) {
transcriptor.send(data, { binary: true }); //kald
}
}
streamData.wstream.write(data);
})
......@@ -187,8 +191,10 @@ module.exports = config => {
resume.endStream(streamData)
delete userAudioEvents['audio_from_' + userId]
if (config.asd) {
transcriptor.streamDisconnect(thisUserStream)
if (config.asd.used) {
asd.streamDisconnect(transcriptor)//asd
} else {
transcriptor.close() //kaldis
}
})
})
......@@ -203,7 +209,6 @@ module.exports = config => {
const stompClient = createStompClient();
audioSocket(resume)
const proxyEndpointServer = http.createServer();
const wssServer = new WebSocket.Server({
......
......@@ -48,8 +48,8 @@ module.exports = (config, resumeConfig) => {
entries: []
}
for(var i = 0;i < lines.length;i++){
var data = lines[i].split(' ');
for(var i = 0;i < lines.length - 1;i++){
var data = lines[i].replace(/\\/gi,"").split(' ');
const speaker = data[1]
const from = data[2]
......@@ -71,6 +71,7 @@ module.exports = (config, resumeConfig) => {
}
function offlineTranscription(enhancementlCallback) {
//const url = 'http://10.31.130.8:5000/upload'
const url = 'http://' + config.host + ':' + config.port + '/' + config.api.upload;
const uiid = uuidv1();
......@@ -84,7 +85,7 @@ module.exports = (config, resumeConfig) => {
wavFile: {
value: fs.ReadStream(config.folder.audioMerged+'/merged.wav'),
options: {
filename: myUuidString,
filename: 'merged.wav',
contentType: 'audio/x-wav'
}
},
......@@ -93,17 +94,20 @@ module.exports = (config, resumeConfig) => {
encoding: null
};
console.log('POST OFFLINE TRANSCRIPTION')
request.post(options, enhancementlCallback);
}
function resume(json){
const url = 'http://' + resumeConfig.hostName + '/' + resumeConfig.api+'?id=test'+resumeConfig.query;
const url = 'http://' + resumeConfig.hostName + '/' + resumeConfig.api+'?id=test'+resumeConfig.query;
const options = {
uri: url ,
method: 'POST',
json
};
console.log('POST RESUME')
request(options, function (error, response, body) {
if (!error && response.statusCode == 200) {
fs.writeFile(resumeConfig.resumeFolder+'/resume.txt' , util.inspect(body), 'utf-8')
......@@ -115,13 +119,19 @@ module.exports = (config, resumeConfig) => {
function resumeGenerator() {
let nbFile = 0;
let memoryFile;
let cmd = ffmpeg()
fs.readdirSync(config.folder.audioMerged).forEach(file => {
cmd.input(config.folder.audioMerged + "/" + file)
nbFile++;
memoryFile = file;
})
if(nbFile !== 1) {
memoryFile = "/merged.wav"
}
cmd.complexFilter('amix=inputs=' + nbFile + ':duration=first:dropout_transition=3')
.save(config.folder.audioMerged + "/merged.wav")
.save(config.folder.audioMerged + "/"+memoryFile)
.on('end', function () {
offlineTranscription((err, response, body) => {
let result;
......@@ -130,14 +140,10 @@ module.exports = (config, resumeConfig) => {
} else if (response === undefined || body === undefined || response.statusCode !== successCode) {
result = {module: 'Offline transcription', error: 'Error during audio transcription'}
}
const json = JSON.parse(body);
if (json.status === 5) {
result = {module: 'Offline transcription', error: 'Error during audio transcription'}
}
console.log('current transcription ', json.transcript.transcription)
var textChunk = body.toString('utf8');
const jsonTranscript = parserTranscription(json.transcript.transcription)
const jsonTranscript = parserTranscription(textChunk)
resume(jsonTranscript)
})
})
......@@ -209,7 +215,7 @@ module.exports = (config, resumeConfig) => {
})
.on('end', function () {
console.log('Merging finished !' + streamData.fileName);
if (--userConf === 0) {
if (--userConf === 0 && resumeConfig.isUse === true) {
console.log('generate room audio')
resumeGenerator(config)
}
......
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