PerformanC / FastLink

The NodeJs Lavalink client.
BSD 2-Clause "Simplified" License
11 stars 3 forks source link

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

Closed ZuherLaith closed 6 months ago

ZuherLaith commented 6 months ago

FastLink version

2.4.2

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 .ogg file is not playable using FFplay, or even audacity -> Import Raw methods

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

ThePedroo commented 6 months ago

This is not related to FastLink, but to NodeLink itself, could you re-create this issue but in its repository?