voice icon indicating copy to clipboard operation
voice copied to clipboard

High latency buffering of audio before playback

Open lukejriddle opened this issue 2 years ago • 1 comments

Issue description

It takes the AudioPlayer around 800-900ms to fully buffer before finally playing in a voice channel. This is up from <100ms from older versions of Discord.js, using the dispatcher.

I have used tweetnacl and libsodium-wrappers, I have created AudioResources from both local files and remote, latency has not improved.

Steps to reproduce:

  • Use new Date() immediately after a connection to a voice channel, and again on('stateChange') from buffering to playing. Note the difference is ~900ms.

Code sample

const connection = joinVoiceChannel({
    channelId: channel.id,
    guildId: channel.guild.id,
    adapterCreator: channel.guild.voiceAdapterCreator
});

const player = createAudioPlayer();
const resource = createAudioResource(path.join(__dirname, '../../130876312133959680.mp3'));

player.play(resource);
connection.subscribe(player);

player.on('stateChange', (oldState, newState) => {
  if (oldState.status === 'playing' && newState.status === 'idle') {
    connection.disconnect();
  }
});

@discordjs/voice version

0.7.5

Node.js version

v16.13.0

Operating system

Windows

Priority this issue should have

Low (slightly annoying)

lukejriddle avatar Nov 15 '21 03:11 lukejriddle

This bug also often results in the first 800ms or so of audio not being played. My workaround is setting the audio resource volume to inline and adjusting it when I want it to mute or not

botchi09 avatar Dec 30 '21 15:12 botchi09