Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

178
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda