Convert Google text to speech API result to HTTP streamed response
When using the Google Cloud Text-to-Speech API, the default behavior of the synthesizeSpeech() method, as described in the synthesizeSpeech() documentation, is to return the audioContent as a complete buffer.
However, if you want to enable streaming playback for long audios, you can convert the buffer to a file streaming response. To achieve this, you can utilize the PassThrough class from the Node.js Stream API, as outlined in the PassThrough documentation.
Here is a sample snippet from a Nuxt 3 project that demonstrates this: