I am working on a project to get the transcript out of an audio file. Audio files are of the format flac. I am using AWS Lambda and have written the code in node. Also, I am using IBM Speech to text service and using the basic example code given by them which can be found here. The problem is that my lambda function finishes before running these functions.
I am downloading a file from s3 and storing it locally(which is working fine). After that, I am trying to pass the same file to IBM Speech to Text SDK which should return the transcripts of the audio file to the local storage
Here is the code:
const downloadFile = function (url1, dest, cb) {
const file = fs.createWriteStream(dest);
https.get(url1, function (res) {
//res.setEncoding('binary');
res.pipe(file);
file.on('finish', function () {
const stats = fs.statSync(dest);
const fileSizeInBytes = stats.size;
//Convert the file size to megabytes (optional)
const fileSizeInMegabytes = fileSizeInBytes / 1000000.0;
console.log(fileSizeInMegabytes);
file.close();
RunIBMWatson(dest);
callback(null,"Nice");
});
});
};
function RunIBMWatson(dest){
console.log(dest);
console.log("I am here");
const recognizeStream = speech_to_text.createRecognizeStream(params);
fs.createReadStream(dest).pipe(recognizeStream);
recognizeStream.pipe(fs.createWriteStream('/tmp/transcription.txt'));
recognizeStream.setEncoding('utf8');
recognizeStream.on('results', function(event) { onEvent('Results:', event); });
recognizeStream.on('data', function(event) { onEvent('Data:', event); });
recognizeStream.on('error', function(event) { onEvent('Error:', event); });
recognizeStream.on('close', function(event) { onEvent('Close:', event); });
recognizeStream.on('speaker_labels', function(event) { onEvent('Speaker_Labels:', event); });
function onEvent(name, event) {
console.log("I am in onEvent");
if (name === 'data'){
console.log(event);
}
and Here is the function logs that I get from AWS Lambda:
2018-03-05 03:31:53.585 54.093469
2018-03-05 03:31:53.588 /tmp/sample.flac
2018-03-05 03:31:53.588 I am here
I am a starter in both AWS Lambda and Node. So if anyone can point out the mistake I am making.