Skip to content

AudioDispatcher

classe · Source

The class that sends voice packet data to the voice connection.

js
// 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

readonly

bitrateEditable: boolean

Whether or not the Opus bitrate of this stream is editable Source

volumeEditable

readonly

volumeEditable: boolean

Whether or not the volume of this stream is editable Source

volume

readonly

volume: number

The current volume of the stream Source

volumeDecibels

readonly

volumeDecibels: number

The current volume of the stream in decibels Source

volumeLogarithmic

readonly

volumeLogarithmic: number

The current volume of the stream from a logarithmic scale Source

player

player: MediaPlayer

The Player that controls this dispatcher Source

pausedSince

nullable

pausedSince: number

The time that the stream was paused at (null if not paused) Source

paused

readonly

paused: boolean

Whether or not playback is paused Source

pausedTime

readonly

pausedTime: number

Total time that this dispatcher has been paused in milliseconds Source

totalStreamTime

readonly

totalStreamTime: number

The time (in milliseconds) that the dispatcher has been playing audio for, taking into account skips and pauses Source

Methods

getTypeDispatcher

getTypeDispatcher(): 'audio'

Get the type of the dispatcher Returns: 'audio'Source

setBitrate

setBitrate(value: number): boolean

Set the bitrate of the current Opus encoder if using a compatible Opus stream. Parameters

NameTypeDescription
valuenumberNew 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

setPLP(value: number): boolean

Sets the expected packet loss percentage if using a compatible Opus stream. Parameters

NameTypeDescription
valuenumberbetween 0 and 1

Returns: boolean — Returns true if it was successfully set. Source

setFEC

setFEC(enabled: boolean): boolean

Enables or disables forward error correction if using a compatible Opus stream. Parameters

NameTypeDescription
enabledbooleantrue to enable

Returns: boolean — Returns true if it was successfully set. Source

setSyncVideoDispatcher

setSyncVideoDispatcher(otherDispatcher: VideoDispatcher)

Sync with another video dispatcher to ensure that the audio and video are played at the same time. Parameters

NameTypeDescription
otherDispatcherVideoDispatcherThe video dispatcher to sync with
Source

setVolume

setVolume(volume: number)

Sets the volume relative to the input stream - i.e. 1 is normal, 0.5 is half, 2 is double. Parameters

NameTypeDescription
volumenumberThe volume that you want to set
Source

setVolumeDecibels

setVolumeDecibels(db: number)

Sets the volume in decibels. Parameters

NameTypeDescription
dbnumberThe decibels
Source

setVolumeLogarithmic

setVolumeLogarithmic(value: number)

Sets the volume so that a perceived value of 0.5 is half the perceived volume etc. Parameters

NameTypeDescription
valuenumberThe value for the volume
Source

pause

pause(silence?: boolean)

Pauses playback Parameters

NameTypeDescription
silence?booleanWhether to play silence while paused to prevent audio glitches Default: false.
Source

resume

resume()

Resumes playback Source

createHeaderExtension

createHeaderExtension(): Buffer

Creates a one-byte extension header https://www.rfc-editor.org/rfc/rfc5285#section-4.2Returns: Buffer — <Buffer be de 00 01> Source

createPayloadExtension

createPayloadExtension(): Buffer

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

volumeChange: unknown

Emitted when the volume of this dispatcher changes. Parameters

NameTypeDescription
oldVolumenumberThe old volume of this dispatcher
newVolumenumberThe new volume of this dispatcher
Source

speaking

speaking: unknown

Emitted when the dispatcher starts/stops speaking. Parameters

NameTypeDescription
valuebooleanWhether or not the dispatcher is speaking
Source

error

error: unknown

Emitted when the dispatcher encounters an error. Source

start

start: unknown

Emitted once the stream has started to play. Source

debug

debug: unknown

Emitted whenever the dispatcher has debug information. Parameters

NameTypeDescription
infostringThe debug info
Source

Unofficial software. Not affiliated with or supported by Discord.