Rei-x/discord-speech-recognition

Audio BASE64 Output

Pudochu opened this issue · 3 comments

Hello,

First of all, your module and project are very cool. I am using discord.js@v14 module and discord-speech-recognition latest version.

My problem is is there any way I can get "audio base64" data with speech client event?

client.on("speech", (msg) => {
  // If bot didn't recognize speech, content will be empty
  if (!msg.content) return;

  msg.author.send(msg.content);
});

Kind regards,
Pudochu.

Rei-x commented

Hello, you can get raw PCM audio encoded to base64 like this:

client.on("speech", (msg) => {
    const rawAudioAsBase64 = msg.audioBuffer.toString("base64");
});

In case you want to play it in the browser on send to some API I added function to get wav data encoded as base64 (available in 3.2.0 version):

client.on("speech", (msg) => {
    const wavEncodedAsBase64 = msg.getWavEncodedToBase64Audio();
});

Is this what you want?

Hello, This is what I was looking for! I'm grateful for your help! Thanks so much.

client.on("speech", (msg) => {
    const wavEncodedAsBase64 = msg.getWavEncodedToBase64Audio();
});

However, when I convert it to wav file, the sound is robotic and in slow motion.

Sincerely,
Pudochu.

Hello, i fixed.

VoiceMessage.audioBufferFormat = {
    sampleRate: 48000,
    frameSize: 960,
    channels: 2,
};