Commit 3879e823 authored by Yoann HOUPERT's avatar Yoann HOUPERT
Browse files

add callback rest api

parent b4bf0aa6
...@@ -29,9 +29,8 @@ const enhancement = (wavFile, speechEnhancement, enhancementlCallback) => { ...@@ -29,9 +29,8 @@ const enhancement = (wavFile, speechEnhancement, enhancementlCallback) => {
if (!speechEnhancement.debug) { if (!speechEnhancement.debug) {
return request.post({url, form: formData}, enhancementlCallback); return request.post({url, form: formData}, enhancementlCallback);
}else {
return wavFile;
} }
return wavFile;
}; };
module.exports = { module.exports = {
......
...@@ -20,17 +20,7 @@ ...@@ -20,17 +20,7 @@
const request = require('request'); const request = require('request');
function sttCallback(err, httpResponse, body) { const transcript = (audio, gstreamer, sttCallback) => {
if (err) {
return console.error('upload failed:', err);
}
return body;
}
const transcript = (audio, gstreamer) => {
const formData = {
audiofile: audio
};
const url = 'http://' + gstreamer.host + ':' + gstreamer.port + '/' + gstreamer.api.recognize; const url = 'http://' + gstreamer.host + ':' + gstreamer.port + '/' + gstreamer.api.recognize;
// TODO until no docker-compose use debug mode // TODO until no docker-compose use debug mode
return request.post({url, body: audio}, sttCallback); return request.post({url, body: audio}, sttCallback);
......
...@@ -33,22 +33,23 @@ const routesFactory = config => { ...@@ -33,22 +33,23 @@ const routesFactory = config => {
return res.status(400).send('File is not valid.'); return res.status(400).send('File is not valid.');
} }
let wavEnhancement = req.files.wav.data; enhancer.enhancement(req.files.wav, config.speechEnhancement,
/*wavEnhancement = enhancer.enhancement(req.files.wav, config.speechEnhancement,
(err, httpResponse, body) => { (err, httpResponse, body) => {
if (err) { if (err) {
return res.status(400).send('Error while enhancing audio.'); return res.status(400).send('Error while enhancing audio.' + err);
} }
console.log('Upload successful!');
console.log(body)
//res.send(body);
return res.status(200).json({message: 'transcript call', transcript: 'toto'});
}
);*/
const transcriptRes = stt.transcript(wavEnhancement, config.gstreamer); // TODO Manage 'body' raw for kaldis api
return res.status(200).json({message: 'transcript call', transcript: 'toto'});
stt.transcript(req.files.wav.data, config.gstreamer,
(err, httpResponse, body) => {
if (err) {
return res.status(400).send('Error while enhancing audio.' + err);
}
return res.status(200).json({message: 'transcript done', transcript: JSON.parse(body).hypotheses[0].utterance});
});
}
);
}); });
return routes; return routes;
}; };
......
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