PerformanC / NodeLink

Performant LavaLink alternative written with Node.Js
BSD 2-Clause "Simplified" License
38 stars 23 forks source link

[BUG]: Recording Voice via base64Voice Isn't Working #39

Closed ZuherLaith closed 5 months ago

ZuherLaith commented 5 months ago

NodeLink version

2.0.1

Description

I'm running into a trouble with the "record" method used in FastLink When using "record stop" the voice-xxxx.ogg is saved in root directory. The issue is this .ogg file is not playable using FFplay, or even audacity -> Import Raw methods

Client

2.4.2

Steps to reproduce

Using the example file I created here, please make tests on playing it.

Example code

if (args[0] === 'start') { const player = new FastLink.player.Player(message.guild.id);

          if (player.playerCreated() === false) {
              message.channel.send('No player found.');
              return;
          }

          const voiceEvents = player.listen();

          voiceEvents.on('endSpeaking', (voice) => {
              const base64Voice = voice.data;
              const buffer = Buffer.from(base64Voice, 'base64');

              // Check if the file exists before reading it
              try {
                  const previousVoice = fs.readFileSync(`./voice-${message.author.id}.ogg`);
                  // File exists, append the new voice data
                  fs.writeFileSync(`./voice-${message.author.id}.ogg`, Buffer.concat([previousVoice, buffer]));
              } catch (error) {
                  if (error.code === 'ENOENT') {
                      // File does not exist, create a new file with the voice data
                      fs.writeFileSync(`./voice-${message.author.id}.ogg`, buffer);
                  } else {
                      // Other error occurred, handle it appropriately
                      console.error('Error reading or writing file:', error);
                  }
              }
          });
          message.channel.send('Started recording. Be aware: This will record everything you say in the voice channel, even if the bot is deaf. Server deaf the bot if you don\'t want to be recorded by any chances.');
        }

        if (args[0] === 'stop') {
          const player = new FastLink.player.Player(message.guild.id)

          if (player.playerCreated() === false) {
            message.channel.send('No player found.')

            return;
          }

          player.stopListen()

          message.channel.send('Stopped recording.')
        }

Confirmations

Code of Conduct

ThePedroo commented 5 months ago

This will be addressed together with an addition for pcm type to make development for TTS easier.