Git Product home page Git Product logo

soundonly-discord-bot's Introduction

SoundOnly Discord bot

This is a proof-of-concept. And so far it's not even a great proof.

The goal is to stream the sound from local PC sound devices in a simple and straightforward manner. Not intended to scale - one owner, one stream at a time is good enough.

Dependencies

  • DSharpPlus version 4 (manual actions needed to provide VoiceNext requirements);
  • NAudio.

Configuration

After the first run with no config file, the app will create a dummy config (bot_config.json in the same folder) and exit. Fill the config with your own bot token and command prefix.

Available commands

  • wavein - uses WaveInEvent to get audio from capture devices (microphones and such);
  • wasapi - uses WasapiCapture to get audio from capture devices (microphones and such);
  • loopback - uses WasapiLoopbackCapture to get audio from "render" devices (speakers and such);
  • ffmpeg - uses ffmpeg process to get audio from capture devices (put ffmpeg.exe near the bot binary);
  • leave - stop any active stream and leave voice channel.

All activating commands have an optional argument. Instead if seeing the device list and replying with a number every time, the number can be provided as an argument.

Notes

Virtual Audio Cable and/or Voicemeeter are extremely handy to route local sounds.

NAudio is a poorly documented mess. CSCore seems to have more polish, but it haven't made the transition to .NET Core yet, and it's questionable whether it will ever be able to do it. Activity on that project is quite low at the moment. (The project name now looks quite ironic.)

Challenges

  • Some sound devices don't want to cooperate. Expect crashes. So far I didn't try to recover from such failures - I want no ensure I can have working devices to work properly in the first place;

  • It's not always possible to have WaveFormat you need (Discord requires PCM / 48000 Hz / 16 bps / stereo). WaveInEvent is the easiest in that sense - it is able to return data in requested format for all devices I tested. WasapiLoopbackCapture don't have wave format settings - have to deal with what it returns. WasapiCapture was able to use the required format only for one microphone and returned a completely oddball format when requested for the "closest" format for any other devices;

  • NAudio is like a set of incompatible bricks. In case of WasapiLoopbackCapture and WasapiCapture I had to come up with format transformations - I'm not sure they are the most efficient ones. You might also need a different set of transformations depending on your PC configuration. I stopped with what "works" for me;

  • The major issue is that this bot does not achieve the transmission quality suitable for music streaming. Sound glitches happen ever so often even with WaveInEvent. So far I'm not entirely sure if there is a single root cause that can be removed and make the whole thing meaningful for further improvement;

  • ASIO support from NAudio left unimplemented. It requires single-threaded apartment state. Not worth an effort unless the above issue is sorted out first. Also can't just slap [STAThread] on top of Main();

  • It might be interesting idea to handle the return channel and allow to use this as a voice gateway. It might suffice for voice comms the way it is already. But it wasn't my goal, so I leave it for "maybe later";

  • CSCore can be used despite the lack of .NET Core support. It doesn't solve the sound issues though (cscore branch of this repo);

  • FFmpeg can be used to capture sound in a way similar to playing files. It produces somewhat better result than all other attempts so far, but still not usable.

  • New DSharpPlus.VoiceNext implementation is fully async and it works against realtime applications.

License

MIT

soundonly-discord-bot's People

Contributors

killymxi avatar

Stargazers

 avatar

Watchers

 avatar

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.