0

Google text to speech returns the output audio as base64 string. I want to save that string into firebase storage. The following code saves the sting as base text not as binary and so not playable. This could is written in a Firebase cloud function.

let buffer = Buffer.from(audioRespose.data.audioContent);
  let file = storage.bucket("bucketname").file("audio7.mp3");

  await file.save(buffer, {
    metadata: { contentType: "audio/mpeg" },
    public: true,
  }).catch((errSave) => {
    response.status(500).send(errSave);
    return;
  });
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
MSaudi
  • 4,442
  • 2
  • 40
  • 65
  • 1
    It looks like you need to specify that the audio content is in base64 encoding when you read it from the stream. See https://stackoverflow.com/questions/42879012/how-do-i-upload-a-base64-encoded-image-string-directly-to-a-google-cloud-stora and https://stackoverflow.com/questions/14573001/nodejs-how-to-decode-base64-encoded-string-back-to-binary – Frank van Puffelen Mar 09 '21 at 15:33
  • @FrankvanPuffelen that did the job. Thank you very much :) – MSaudi Mar 09 '21 at 16:31
  • Thanks for confirming! – Frank van Puffelen Mar 09 '21 at 16:53

0 Answers0