AudioDispatcher
classe · Source
The class that sends voice packet data to the voice connection.
// Obtained using:
client.voice.joinChannel(channel).then(connection => {
// You can play a file or a stream here:
const dispatcher = connection.playAudio('/home/hydrabolt/audio.mp3');
});Extends: BaseDispatcherImplements: VolumeInterface
Properties
bitrateEditable
Whether or not the Opus bitrate of this stream is editable Source
volumeEditable
Whether or not the volume of this stream is editable Source
volume
The current volume of the stream Source
volumeDecibels
The current volume of the stream in decibels Source
volumeLogarithmic
The current volume of the stream from a logarithmic scale Source
player
The Player that controls this dispatcher Source
pausedSince
The time that the stream was paused at (null if not paused) Source
paused
Whether or not playback is paused Source
pausedTime
Total time that this dispatcher has been paused in milliseconds Source
totalStreamTime
The time (in milliseconds) that the dispatcher has been playing audio for, taking into account skips and pauses Source
Methods
getTypeDispatcher
Get the type of the dispatcher Returns: 'audio'Source
setBitrate
Set the bitrate of the current Opus encoder if using a compatible Opus stream. Parameters
| Name | Type | Description |
|---|---|---|
value | number | New bitrate, in kbps If set to 'auto', the voice channel's bitrate will be used |
Returns: boolean — true if the bitrate has been successfully changed. Source
setPLP
Sets the expected packet loss percentage if using a compatible Opus stream. Parameters
| Name | Type | Description |
|---|---|---|
value | number | between 0 and 1 |
Returns: boolean — Returns true if it was successfully set. Source
setFEC
Enables or disables forward error correction if using a compatible Opus stream. Parameters
| Name | Type | Description |
|---|---|---|
enabled | boolean | true to enable |
Returns: boolean — Returns true if it was successfully set. Source
setSyncVideoDispatcher
Sync with another video dispatcher to ensure that the audio and video are played at the same time. Parameters
| Name | Type | Description |
|---|---|---|
otherDispatcher | VideoDispatcher | The video dispatcher to sync with |
| Source |
setVolume
Sets the volume relative to the input stream - i.e. 1 is normal, 0.5 is half, 2 is double. Parameters
| Name | Type | Description |
|---|---|---|
volume | number | The volume that you want to set |
| Source |
setVolumeDecibels
Sets the volume in decibels. Parameters
| Name | Type | Description |
|---|---|---|
db | number | The decibels |
| Source |
setVolumeLogarithmic
Sets the volume so that a perceived value of 0.5 is half the perceived volume etc. Parameters
| Name | Type | Description |
|---|---|---|
value | number | The value for the volume |
| Source |
pause
Pauses playback Parameters
| Name | Type | Description |
|---|---|---|
silence? | boolean | Whether to play silence while paused to prevent audio glitches Default: false. |
| Source |
resume
Resumes playback Source
createHeaderExtension
Creates a one-byte extension header https://www.rfc-editor.org/rfc/rfc5285#section-4.2Returns: Buffer — <Buffer be de 00 01> Source
createPayloadExtension
Creates a one-byte extension header & a single extension of type playout-delay Returns: Buffer — playout-delay extension <Buffer 51 00 00 00> Source
Events
volumeChange
Emitted when the volume of this dispatcher changes. Parameters
| Name | Type | Description |
|---|---|---|
oldVolume | number | The old volume of this dispatcher |
newVolume | number | The new volume of this dispatcher |
| Source |
speaking
Emitted when the dispatcher starts/stops speaking. Parameters
| Name | Type | Description |
|---|---|---|
value | boolean | Whether or not the dispatcher is speaking |
| Source |
error
Emitted when the dispatcher encounters an error. Source
start
Emitted once the stream has started to play. Source
debug
Emitted whenever the dispatcher has debug information. Parameters
| Name | Type | Description |
|---|---|---|
info | string | The debug info |
| Source |