Create audio file from URL

Asked

Viewed 657 times

0

I need the messenger audio file to use in the Google Cloud Speech API. When an audio is received in the messenger, a url is generated that downloads that file into . mp4. How can I from that url recover the audio, and use in the Google API?

  • In Node I’m still researching, but in Java I had to implement something similar in a project. For simple I had to open only an Inputstream receiving a URL Object and calling the openStream() method, InputStream input = new URL("http://www.somewebsite.com/a.txt").openStream();

  • I found a blog with an interesting post about: [link]https://subvisual.co/blog/posts/39-tutorial-html-audio-capture-streaming-to-node-js-no-browser-extensions[link]

1 answer

1

The trick here is to take streams, with the http module (or equivalent) 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);
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.