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