Rei-x / discord-speech-recognition

Speech to text extension for discord.js
https://npmjs.com/package/discord-speech-recognition
MIT License
56 stars 22 forks source link

Audio BASE64 Output #48

Closed Pudochu closed 1 year ago

Pudochu commented 1 year ago

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 1 year ago

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?

Pudochu commented 1 year ago

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.

Pudochu commented 1 year ago

Hello, i fixed.

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