discordjs / discord.js

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

Progressively worse audio streaming lag #5118

Closed newperson1746 closed 3 years ago

newperson1746 commented 3 years ago

Please describe the problem you are having in as much detail as possible: Using 12.5.1 (latest stable), latency from streaming live audio becomes progressively worse; it begins at a fairly great 0.1 seconds before reaching over 20 seconds after about 6 hours of streaming.

Include a reproducible code sample here, if possible: Main test program: https://github.com/newperson1746/discord-ambience-bot using the v12 api, updated by myself from https://github.com/VTTAssets/discord-ambience-bot which uses the v11 api (thinking that the v11-->v12 update would fix the latency, but it didnt)

Further background: I updated the discord-ambience-bot to the v12 api after reading both #2461 and https://stackoverflow.com/questions/57718532/issues-with-playing-audio-over-voice-channel-audio-is-truncated-and-each-file-i which reference latency issues with a bad voice implementation in v11. The latency is actually worse in v12 than the discord-ambience-bot on v11; after 6 hours v11 was only up to about 15 seconds while v12 was far past 20 seconds of latency.

// Place your code here (full code is part of the git repo above)

// pipe the audio input into the transform stream and
          ai.pipe(stream);
          // the transform stream into the discord voice channel
          const dispatcher = connection.play(stream, { type: 'converted', bitrate: '128000', highWaterMark: '1' });
          // start audio capturing
          ai.start();

Further details:

Relevant client options:

Note: highWaterMark does not actually let me set "1", it tells me that any value below 12 is too low. I mention this because a low value means less cached opus packets or something like that, which would help the latency. However, there seems to be no limit to the lag, it keeps increasing indefinitely thus probably not just building up a set number of cached packets.

amishshah commented 3 years ago

Hi there,

We're working on a new implementation of Discord's Voice API that has better playback quality and is more reliable than what we currently support in Discord.js v12 - check it out at https://github.com/discordjs/voice!

The new library solves many of the issues that users are facing, and as part of this, we're dropping built-in support for voice in our next major release. We have a PR (https://github.com/discordjs/discord.js/pull/5402) that adds native support for our new voice library - once this PR is merged, this issue will be closed.

You can still use our new voice library before that PR lands - just take a look at our music bot example to see how to get started upgrading your voice code. By using the boilerplate music player in the example, you can make it even easier to upgrade your code.

Note that the PR above only reduces some of the boilerplate code you'd otherwise have to write - you do not have to wait for the PR to be merged to start using the new voice library.


If you have any questions about this, feel free to: