I have developed nodejs-client that replaces Javaclient provided with AVS (Alexa Voice Service) sample code.
The code used makes a post request, and pipes the output mp3 to file. But many a times output mp3 is not complete and its broken from the end, and sometimes from the beginning. So for eg. desired mp3 file duration is 9sec, sometimes output file is 8sec long or 6sec long, or complete 9sec long.
Its random behaviour.
Code used to make api request and redirect o/p to file is as below. Let me know whats wrong here, I am new to request piping.
var options = {
url: 'https://access-alexa-na.amazon.com/v1/avs/speechrecognizer/recognize',
headers:{
'Content-Type':'multipart/form-data',
'Transfer-Encoding':'chunked'
},
formData: formData
};
var destination = fs.createWriteStream(path.join(__dirname,outputfile));
//request.debug = 1;
request.post(options, function optionalCallback(err, httpResponse, body) {
//console.log(httpResponse);
if(body.length < 100){
console.log(body);
}
console.log("\n\r----Processing Done to ("+outputfile+")----");
if(loadingInt!=null)clearInterval(loadingInt);
process.exit();
if (err) {
return console.error('upload failed:', err);
}
//console.log('Upload successful! Server responded with:', body);
}).auth(null, null, true, token)
.pipe(destination);
I had raised this with AVS guys, but they told its issue with code, and ot their api.
The problem is the
process.exit()call. Not sure why that is in there at all. Theexitcall sometimes is exiting your process before the piping is completed.