Create audio file, from URL

0

I need the messenger audio file, for use in the api Google Cloud Speech API. When an audio is received in the messenger, a url is generated that downloads this file in .mp4. How can I from this url retrieve the audio, and use it in the Google API?

    
asked by anonymous 08.10.2016 / 01:04

1 answer

1

The trick here is to get into streams, with the http (or equivalent) module to download the audio file and then pipe to a stream, and then do whatever you want. In this example, save to a file:

var http = require('http');
var fs = require('fs');

var audioUrl = "http://www.exemplo/audio.mp4",
    fileName = "audio.mp4";

var file = fs.createWriteStream(fileName);
var request = http.get(audioUrl, function(response) {
  response.pipe(file);
});
    
21.10.2016 / 09:42