Commit 32ec84d7 authored by Yoann HOUPERT's avatar Yoann HOUPERT
Browse files

add generator wav

parent 28bc87bd
Pipeline #13043 failed with stage
......@@ -27,6 +27,7 @@ const loader = require('./lib/loader.js')('./client');
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...');
......@@ -43,7 +44,7 @@ loader.loadAll('controller', 'lib', 'robot')
console.log('App listening on port 3000');
});
proxy.create();
proxy.create(resumeGenerator);
})
.catch(err => {
console.error(err);
......
......@@ -111,11 +111,16 @@ robot = {
getUserStream(easyrtcid) {
robotController.getRemoteStream(easyrtcid).then(stream => {
if (stream !== undefined) {
robot.participantsMediaRecorders[easyrtcid] = robot.processAudio(stream, e => robot.recordedParticipantsWS[easyrtcid].send(e.data), 100);
robot.participantsMediaRecorders[easyrtcid] = robot.processAudio(stream, e => robot.audioGenerator(easyrtcid, e), 100);
}
});
},
audioGenerator(easyrtcid, e) {
robot.recordedParticipantsWS[easyrtcid].send(e.data);
},
recordParticipant(easyrtcid) {
robot.openSTTSocket(easyrtcid);
robot.getUserStream(easyrtcid);
......
......@@ -47,5 +47,20 @@
},
"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",
"audioMerged" : "audio_merged"
},
"audio":{
"format": "wav",
"bitrate": "16k",
"channels": 1,
"srate": 16000
},
"host": "hublot_offline_1",
"port": 9999
}
}
......@@ -54,14 +54,18 @@ module.exports = config => {
return stompCapsule;
}
function kaldiWS(connectionToClient) {
function kaldiWS(connectionToClient, resume) {
const connectionToKaldi = new WebSocket(config.services.kaldi);
connectionToKaldi.on('open', () => {
const streamData = resume.generateStream();
connectionToClient.on('message', message => {
connectionToKaldi.send(message, {
binary: true
});
streamData.wstream.write(message);
});
connectionToKaldi.on('message', message => {
try {
connectionToClient.send(message);
......@@ -72,7 +76,10 @@ module.exports = config => {
});
connectionToClient.on('close', () => connectionToKaldi.close());
connectionToKaldi.on('close', () => connectionToClient.close());
connectionToKaldi.on('close', () => {
resume.endStream(streamData)
connectionToClient.close()
});
});
}
......@@ -120,7 +127,7 @@ module.exports = config => {
}
} else {
console.error('Online reco: error trying to reach http://%s:%s/resources',
config.services.reco.host, config.services.reco.port);
config.services.reco.host, config.services.reco.port);
}
connectionToClient.close();
}
......@@ -138,7 +145,9 @@ module.exports = config => {
}
return {
create: () => {
create: (resume) => {
resume.createFolder()
const server = http.createServer();
const stompClient = createStompClient();
......@@ -150,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 ffprobeInstaller = require('@ffprobe-installer/ffprobe');
const ffmpeg = require('fluent-ffmpeg');
ffmpeg.setFfmpegPath(ffmpegInstaller.path);
ffmpeg.setFfprobePath(ffprobeInstaller.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) => {
const toSecond = 1000
streamData.wstream.close();
let delay = ((timestamp - streamData.timestamp) / toSecond) * -1;
try{
//var silence = ffmpeg().input('anullsrc=sample_rate=16000').inputFormat('lavfi').duration(delay).output(config.folder.audio+"/silence_"+streamData.fileName+".wav").run();
//var stream = ffmpeg(streamData.pathFile).toFormat(config.audio.format).noVideo().audioBitrate(config.audio.bitrate).audioChannels(config.audio.channels).audioFrequency(config.audio.srate).save(config.folder.audio+"/"+streamData.fileName+".wav")
ffmpeg()
.input('anullsrc=sample_rate='+config.audio.srate)
.inputFormat('lavfi')
.duration(delay)
.output(config.folder.audio+"/silence_"+streamData.fileName+".wav")
.on('end', function() {
ffmpeg(streamData.pathFile)
.toFormat(config.audio.format)
.noVideo()
.audioBitrate(config.audio.bitrate)
.audioChannels(config.audio.channels)
.audioFrequency(config.audio.srate)
.save(config.folder.audio+"/"+streamData.fileName+".wav")
.on('end', function() {
ffmpeg()
.input(config.folder.audio+"/silence_"+streamData.fileName+".wav")
.input(config.folder.audio+"/"+streamData.fileName+".wav")
.on('error', function(err) {
console.log('An error occurred: ' + err.message);
})
.on('end', function() {
console.log('Merging finished !');
})
.mergeToFile(config.folder.audioMerged+"/"+streamData.fileName+".wav", config.folder.audio)
})
})
.run()
/*
ffmpeg(streamData.pathFile)
.toFormat(config.audio.format)
.noVideo()
.audioBitrate(config.audio.bitrate)
.audioChannels(config.audio.channels)
.audioFrequency(config.audio.srate)
.save(config.folder.audio+"/"+streamData.fileName+".wav")*/
} catch(err){
// Sometimes, the client will close the connection unexpectedly
// (e.g. when stopping). This is expected
}
}
};
};
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