discordjs / discord.js

A powerful JavaScript library for interacting with the Discord API
https://discord.js.org
Apache License 2.0
25.09k stars 3.94k forks source link

Error [ERR_STREAM_PUSH_AFTER_EOF] ( Discord v12 ) #2678

Closed Gregory-Hepicloud closed 5 years ago

Gregory-Hepicloud commented 5 years ago

Please describe the problem you are having in as much detail as possible: On speak error in console ( v12 discord.js ) connection.on('speaking', (user, speaking) ( i dont have this error in stable version )

Error:

events.js:167
      throw er; // Unhandled 'error' event
      ^

Error [ERR_STREAM_PUSH_AFTER_EOF]: stream.push() after EOF
    at readableAddChunk (_stream_readable.js:253:30)
    at Readable.push (_stream_readable.js:220:10)
    at PacketHandler.push (/var/botv2/node_modules/discord.js/src/client/voice/receiver/PacketHandler.js:82:12)
    at Socket.VoiceReceiver.connection.sockets.udp.socket.on.buffer (/var/botv2/node_modules/discord.js/src/client/voice/receiver/Receiver.js:24:77)
    at Socket.emit (events.js:182:13)
    at UDP.onMessage [as onmessage] (dgram.js:670:8)
Emitted 'error' event at:
    at readableAddChunk (_stream_readable.js:253:16)
    at Readable.push (_stream_readable.js:220:10)
    [... lines matching original stack trace ...]
    at UDP.onMessage [as onmessage] (dgram.js:670:8)

My code :

      connection.on('speaking', (user, speaking) => {
        if (speaking) {

          console.log("listen on");
          const voiceReceiver = connection.createReceiver();
          const audioStream = voiceReceiver.createStream(user); // i have only change this createPCMStream)
          const streamOptions = {
            seek: 0,
            volume: 1
          };
          const fileStream = fs.createWriteStream('/var/botv2/recordings/audiotest.pcm');
          audioStream.pipe(fileStream);

          audioStream.on('end', () => {
            ffmpeg('/var/botv2/recordings/audiotest.pcm')
              .addInputOptions([
                '-f s32le',
                '-ar 48k',
                '-ac 1'
              ])
              .on('end', function() {
                // Stream the file to be sent to the wit.ai
                wavFileInfo.infoByFilename('/var/botv2/recordings/audiotest.wav', function(err, info) {
                  if (err) throw err;
                  if (info.duration > 1.0) {
                    console.log("ok j'envoie au serveur");
                    var stream = fs.createReadStream('/var/botv2/recordings/audiotest.wav');

                    // Its best to return a promise
                    var parseSpeech = new Promise((ressolve, reject) => {
                      // call the wit.ai api with the created stream
                      WitSpeech.extractSpeechIntent(WIT_API_KEY, stream, content_type,
                        (err, res) => {
                          if (err) return reject(err);
                          ressolve(res);
                        });
                    });

                    // check in the promise for the completion of call to witai
                    parseSpeech.then((data) => {
                        console.log("you said: " + data._text);
                        switch (data._text) {
                          // musique
                          case 'remets la musique':
                            return resumeSong(msg);
                          case 'mets en pause la musique':
                            return pauseSong(msg);
                          case 'quel est le titre':
                            return nowPlaying(msg);
                          case 'quelle est la playlist':
                            return printQueue(msg);
                          case 'Alexis le connard':
                          break;
                        }
                        //return data;
                      })
                      .catch((err) => {
                        console.log(err);
                        //return null;
                      })
                  } else {
                    console.log("bruit de fond");
                  }
                });

              })
              .on('error', function(err) {
                console.log('an error happened: ' + err.message);
              })
              .addOutput('/var/botv2/recordings/audiotest.wav')
              .run();
          });

        }
      });

Further details:

Gregory-Hepicloud commented 5 years ago

Hi, Any fix for now ?

amishshah commented 5 years ago

Hi, I'm still trying to reproduce this error, can you elaborate on which OS you're using?

amishshah commented 5 years ago

Hi, I think I've fixed this in the above commit, could you try it out and tell me if it works for you? Also, you should try to create one receiver per connection, not every time a user starts speaking!

Gregory-Hepicloud commented 5 years ago

Hi, , now its work ! im using debian 8 only ssh no graphic

amishshah commented 5 years ago

Awesome! I'll close this issue then, thanks for reporting it! :)