I am working with Google Text To Speech (TTS) in order to save a generated binary audio file to Google Cloud Storage (GCS).
Saving a local binary file d
Same answer, my code:
const http = require('http');
const fs = require('fs');
const path = require('path');
const os = require('os');
var options = {
destination: ('Audio/' + longLanguage + '/' + pronunciation + '/' + word + '.mp3'),
contentType: 'audio/' + audioType
};
function oedPromise() {
return new Promise(function(resolve, reject) {
const tempFile = path.join(os.tmpdir(), (word + '.mp3'));
const file = fs.createWriteStream(tempFile)
http.get(apiURL, function(response) {
response.pipe(file)
.on('error', function(error) {
console.error(error);
reject(error);
})
.on('finish', function() {
myBucket.upload(tempFile, options)
.then(function(data) {
return;
})
.catch(error => console.error(error));
});
});
});
}