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.