discord-audio-stream
v0.7.3510721
Published
Discord library to make stream any audio easier.
Maintainers
Readme
Discord Audio Stream
This module is designed to work with discord.js/voice v0.19. This package doesn't support older versions!
Designed for 24/7 audio playing on discord.
Discord has many unwanted rate limits, especially in the audio area. This package does all the work and ensures that your music never stops playing due to ffmpeg or Discord, with as little effort as possible.
Recommended best Practise:
Create a global Map<GuildId, AudioManager> (Map<KEY, OBJ>) list. When the feature is used on a guild, add a new instance of AudioManager to the Map. When starting the connection or audio, overwrite the respective configuration with the override methods provided. To finally start, use the respective method. For each call and each change, retrieve the AudioManager object from the list and perform your actions. When the feature get stopped, first execute StopConnection and then Dispose to save as much power as possible. Garbage collection does the rest.
For large features: For large systems, it is recommended to queue each start with the packet p-queue, to give ffmpeg enough time..
👋 Support
Please create an issue on github or write
fraujulian on discord!
📝 Usage
Installation
Node.js 22.12.0 or newer is required.
npm install discord-audio-stream
yarn add discord-audio-stream
pnpm add discord-audio-stream
bun add discord-audio-streamRequired Dependencies
You only need to install
libsodium-wrappersif your system does not supportaes-256-gcm(verify by runningrequire('node:crypto').getCiphers().includes('aes-256-gcm')).@snazzah/daveyopusscriptprism-media- @discordjs/voice
- FFmpeg (one of those)
FFmpeg(environment) - recommendedFFmpeg-static(library)
AudioManager Instance
Constructor
AudioManager(ffmpegMode: string, renewInMs, number, connectionData: VoiceConnectionDataModel, audioData: VoiceAudioDataModel): IDisposable, IAudioManagerffmpegMode: 'Native' or 'Standalone'- Native:
FFmpeg(environment) - Standalone:
FFmpeg-static(library)
- Native:
renewInMs: renewal time, default 1,5h = 5400000ms - optionalconnectionData: options for voice connection - optionalaudioData: options for audio player - optional
Example
let audioManager = new AudioManager(
'Native',
5400000,
{
VoiceChannelId: 0, //voice channel id where to play music
GuildId: 0, //guild id
VoiceAdapter: 0, //guild VoiceAdapter
},
{
ResourceType: '', //resource type like link or file
Resource: '', //auto play link or file name
},
);Fields and Methods of AudioManager
Fields
| Name | Type | Security | Description |
| --------- | -------- | --------- | ------------------------------------- |
| Active | bool | protected | To check if the connection is active. |
| Playing | bool | protected | To check if it is playing audio. |
Methods
| Name | Parameters | Return type | Description |
| ----------------------------- | ------------------------------------------------------- | ------------- | ---------------------------------------- |
| OverrideVoiceConnectionData | connectionData: VoiceConnectionDataModel | void | To override intern connectionData field. |
| OverrideVoiceAudioDataModel | audioData: VoiceAudioDataModel | void | To override intern audioData field. |
| CreateAndPlay | | Promise void | Join channel and start playing audio. |
| CreateConnection | | void | Let it connect to voice channel. |
| PlayAudio | | Promise void | To start playing audio. |
| PauseAudio | | void | Pause the audio, if it is playing |
| ResumeAudio | | void | Resume the audio, if it is paused. |
| SetVolume | volume: number (0 - 100 percent) | void | To set the audio volume. |
| StopConnection | | Promise void | Method to disconnect the voice channel. |
| Dispose | | void | Dispose all data in object. |
📝 Types
- VoiceConnection by discord.js/voice
- AudioPlayer by discord.js/voice
- AudioResource by discord.js/voice
- DiscordGatewayAdapterCreator by discord.js/voice
- VoiceConnectionDataModel by discord-audio-stream
- VoiceAudioDataModel by discord-audio-stream
- IDisposable by discord-audio-stream
- IAudioManager by discord-audio-stream
📋 Contributors:
~ FrauJulian - Julian Lechner - CODEOWNER
🤝 Enjoy the package?
Give it a star ⭐ on github!
