Giter Site home page Giter Site logo

voice's People

Contributors

thepedroo avatar unschooledgamer avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

unschooledgamer

voice's Issues

[BUG]: Lags on Windows compared to djs/voice

Version

1.0.5

Description

Using this on Windows makes the bot sound lag while there's no issue doing the same thing in djs/voice

Steps to reproduce

Try the code provided below and these packages :

  • @discordjs/voice: latest
  • @performanc/voice: latest
  • discord.js: latest
  • libsodium-wrappers: latest
  • opusscript: latest
  • yt-stream: latest

Example code

Using this package :

import { Client, GatewayIntentBits } from 'discord.js';
import perfcVoice from '@performanc/voice';
import prism from 'prism-media';
import ytstream from 'yt-stream';
import config from './config.js';

const ffmpeg = new prism.FFmpeg({
    args: [
      '-loglevel', '0',
      '-analyzeduration', '0',
      '-hwaccel', 'auto',
      '-threads', 2,
      '-filter_threads', 2,
      '-filter_complex_threads', 2,
      '-i', '-',
      '-f', 's16le',
      '-ar', '48000',
      '-ac', '2',
      '-crf', '0'
    ]
});

const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildVoiceStates] });

const connection = perfcVoice.joinVoiceChannel({ guildId: config.guild_id, userId: config.bot_user_id, encryption: 'xsalsa20_poly1305_lite' });

client.on('raw', (data) => {
    switch (data.t) {
        case 'VOICE_STATE_UPDATE': {
            if (data.d.guild_id == config.guild_id && data.d.member?.user.id == config.bot_user_id) {
                connection.voiceStateUpdate({
                    session_id: data.d.session_id
                });
            }

            break;
        }

        case 'VOICE_SERVER_UPDATE': {
            if (data.d.guild_id == config.guild_id) {
                connection.voiceServerUpdate({
                    token: data.d.token,
                    endpoint: data.d.endpoint
                });

                connection.connect();
            }

            break;
        }
    }
});

connection.on('stateChange', async (oldState, newState) => {
    if (newState.status == 'ready') {
        //console.log('Voice connection ready');

        const stream = await ytstream.stream(`https://www.youtube.com/watch?v=dQw4w9WgXcQ`, {
            quality: 'high',
            type: 'audio',
            highWaterMark: 1048576 * 32,
            download: true
        });

        const result = stream.stream.pipe(ffmpeg).pipe(
            new prism.opus.Encoder({
                rate: 48000,
                channels: 2,
                frameSize: 960
            }
        ));
        
        connection.play(result);
    }
});

client.on('ready', async () => {
    console.log(`Logged in as ${client.user.tag}!`);

    const channel = client.channels.cache.get(config.channel_id);

    client.guilds.cache.get(config.guild_id).shard.send(
    {
        op: 4,
        d: {
            guild_id: channel.guildId,
            channel_id: channel.id,
            self_mute: false,
            self_deaf: false
        }
    });
});

client.login(config.token);

Using djs/voice :

import { Client, GatewayIntentBits } from 'discord.js';
import { joinVoiceChannel, createAudioPlayer, createAudioResource, NoSubscriberBehavior } from '@discordjs/voice';
import config from './config.js';

import ytstream from 'yt-stream';

const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildVoiceStates] });

client.on('ready', async () => {
    console.log(`Logged in as ${client.user.tag}!`);

    const channel = client.channels.cache.get(config.channel_id);

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

    const player = createAudioPlayer({
        behaviors: {
            noSubscriber: NoSubscriberBehavior.Play,
        },
    });

    const stream = await ytstream.stream(`https://www.youtube.com/watch?v=dQw4w9WgXcQ`, {
        quality: 'high',
        type: 'audio',
        highWaterMark: 1048576 * 32,
        download: true
    });

    const resource = createAudioResource(stream.stream);

    connection.subscribe(player);

    player.play(resource);
});

client.login(config.token);

Confirmations

  • My environment meets the minimum requirements.
  • I have verified that this is not a duplicate issue.

Code of Conduct

  • I agree to follow this project's Code of Conduct

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.