i don't know if Node.JS has a BETTER api to do this (but i'm surprised if it does not), i don't do Node.js programming myself, but i know how to do this with the normal browser javascript API XMLHttpRequest
, i also know that Node.js support XMLHttpRequest.
the equivalent-ish XMLHttpRequest would be
{
let xhr = new XMLHttpRequest();
xhr.open("GET", "https://gateway-lon.watsonplatform.net/text-to-speech/api/v1/synthesize/?accept=audio/mpeg&text=hello", true);
xhr.responseType = "arraybuffer";
xhr.setRequestHeader("Authorization", "Basic " + btoa("<username>:<password>"));
xhr.onload = function(ev) {
fs.appendFile("hello_world.mp3", xhr.response, {
flag: "wb"
});
};
xhr.send();
}