Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Voice slows down then speeds up after pausing and resuming #2354

Closed
1 of 2 tasks
nekobako opened this issue Feb 23, 2018 · 16 comments
Closed
1 of 2 tasks

Voice slows down then speeds up after pausing and resuming #2354

nekobako opened this issue Feb 23, 2018 · 16 comments

Comments

@nekobako
Copy link

nekobako commented Feb 23, 2018

Please describe the problem you are having in as much detail as possible:
After pausing and resuming a song, the voice often slows down and speeds up then returns to normal.

play()
 | (normal speed)
pause()
 | (paused)
resume()
 | (slow‐motion for a few seconds)
 | (fast-forward for a few seconds)
 | (normal speed)
 : (normal speed)
 :

May be related to #2181

I use [email protected] and [email protected] for voice support.
This issue occurs whether I use ytdl or not.

Include a reproducible code sample here, if possible:
The issue is more likely to occur after pausing and resuming a song repeatedly, so this code repeats it 4 times.

const discord = require('discord.js');
const client = new discord.Client();

client.on('message', async message => {
  const connection = await message.member.voiceChannel.join();
  const dispatcher = connection.play('music.mp3', { volume: 0.05 });
  await wait(3000);

  for(let i = 0; i < 4; i++) {
    dispatcher.pause();
    await wait(1000);
    dispatcher.resume();
    await wait(1000);
  }
});

client.login('my token');

async function wait(time) {
  return new Promise((resolve, reject) => setTimeout(resolve, time));
}

Further details:

  • discord.js version: 12.0.0-dev
  • node.js version: 9.5.0
  • Operating system: Windows 10 / macOS High Sierra
  • Priority this issue should have – please be realistic and elaborate if possible: Low
  • I found this issue while running code on a user account
  • I have also tested the issue on latest master, commit hash: c25ea45
@amishshah
Copy link
Member

This sounds like the file isn't being processed fast enough

@amishshah
Copy link
Member

Does this still occur?

@nekobako
Copy link
Author

This still occurs.
I have recorded the issue on latest master, commit hash: c9c2d66
https://streamable.com/wuvmt

@amishshah
Copy link
Member

amishshah commented Aug 9, 2018

Hi, could you see if this issue still occurs? I can't reproduce it. Also, are you running your bot in Docker or a VM?

@nekobako
Copy link
Author

nekobako commented Aug 9, 2018

Still occurs on the latest master (be56087).
I'm running the bot in my local machine. (neither Docker nor VM)

Node.js version: 10.7.0
ffmpeg-binaries version: 4.0.0
node-opus version: 0.3.0

@amishshah
Copy link
Member

Can you send me the music file you're trying to play? If you don't want to send it here, you could send it to me on Discord (my tag is hydrabolt#0001)

@nekobako
Copy link
Author

This is the original audio file. https://www.dropbox.com/s/eqa38u33pk45n2y/sample.mp3?dl=0
And this is the result with the code above. https://streamable.com/3rnb0

@amishshah
Copy link
Member

Ok, I can finally reproduce this issue using the file you sent me!

@amishshah
Copy link
Member

Ok, after taking a look at what happens in StreamDispatcher and talking to some other library developers, I think it might be an interpolation issue. At the times leading up to and during the speed up, Discord.js isn't sending packets any more frequently than before, so if it's not an interpolation issue I'm not sure what it could be. If anyone has any ideas it would be helpful.

(To make sure this wasn't a Discord.js bug, I tested this in Eris to see if I could reproduce it and it seems to occur there too)

@amishshah
Copy link
Member

Just to confirm this I set packet interval to a fixed 20ms (normally discord.js would adjust this depending on how long it took to send the current packet) and it still occurred, which gives me more belief that it is indeed an interpolation issue.

@amishshah
Copy link
Member

After some consideration I still think this issue isn't Discord.js's -- it's sending packets at the right rate and with the right timestamps and sequences, so I'm putting this down to the Discord client. If I repeatedly play a stream for 3 seconds and pause it for 1 second, I can no longer reproduce this issue; this is already a pretty extreme case. I don't think Discord.js should be responsible for any "glitches" if you decide to play/pause a stream really quickly and repeatedly.

Either way thanks for bringing up this issue and making us aware of it, I'm sorry we can't fix it at the moment. As a workaround you could try emulating pauses by adding silence to your audio file at the times you want it to be paused and then play that, but other than that I don't have any suggestions as to how to fix this for you.

@nekobako
Copy link
Author

OK, Thank you for researching the issue!
I'll try to play silent audio instead of pausing.

@amishshah
Copy link
Member

Actually I think I've just figured out a way to solve this, I'll try and implement it today

amishshah added a commit that referenced this issue Aug 14, 2018
@amishshah
Copy link
Member

Ok, with the above commit you can use .pause(true) to have Discord.js still be paused, but send packets of silence to avoid any weird errors on any receivers.

@nekobako
Copy link
Author

Thank you!
Now there is no glitches even if bot users click ⏯ reaction button repeatedly!

@amishshah
Copy link
Member

Great to hear! 😄

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants