Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

168
Views
Convert Buffer from @google-cloud/text-to-speech and send it to Telegram chat as a voice message

I tried to convert a Buffer from @google-cloud/text-to-speech with audio-decode lib, but it's throwing an error (something like Buffer is not valid). So I find lib ffmpeg but I can't understand how to set input from a variable and then save it to the variable again so I could send it as a Telegram voice message.

The current code of request to @google-cloud/text-to-speech looks like this:

const request = {
    input: {
        text: "TEST TEST TEST TEST",
    },
    // Select the language and SSML voice gender (optional)
    voice: { languageCode: "en-US", ssmlGender: "NEUTRAL" },
    // select the type of audio encoding
    audioConfig: { audioEncoding: "OGG_OPUS" },
};

const [response] = await client.synthesizeSpeech(request);

response is a buffer:

{ audioContent: <Buffer 4f 67 67 53 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 43 5e c1 a1 01 13 4f 70 75 73 48 65 61 64 01 01 38 01 c0 5d 00 00 00 00 00 4f 67 67 ... 23270 more bytes> }

If I understood right, telegram voice message should be in OGG format, but I can get only OGG OPUS, WAV, or MP3: https://cloud.google.com/speech-to-text/docs/encoding

My question is: how can I convert that Buffer to OGG and save it to a variable?

Also, I use Telegraf for Telegram API, if it's important.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!