ManagesPlayback
Outbound-audio concern of {@see \Discord\Voice\VoiceClient}: the play* entry points, the Ogg/DCA read loops, and the playback state controls (speaking, volume, bitrate, pause/stop/reset).
Tags
Table of Contents
Methods
- getDbVolume() : float|int
- The current playback volume expressed in decibels.
- pause() : void
- Pauses the current sound.
- playDCAStream() : PromiseInterface
- Plays a DCA stream.
- playFile() : PromiseInterface
- Plays a file/url on the voice stream.
- playOggStream() : PromiseInterface
- playPcmFile() : PromiseInterface
- Plays a raw PCM file on the voice stream.
- playRawStream() : PromiseInterface
- Plays a raw PCM16 stream.
- setAudioApplication() : void
- Sets the audio application.
- setBitrate() : void
- Sets the bitrate.
- setSpeaking() : void
- Sets the speaking value of the client.
- setVolume() : void
- Sets the volume.
- stop() : void
- Stops the current sound.
- unpause() : void
- Unpauses the current sound.
- readDCAOpus() : void
- Reads and processes a single Opus audio frame from a DCA (Discord Compressed Audio) stream.
- readOggOpus() : void
- Reads Ogg Opus packets and sends them to the voice server.
- reset() : void
- Resets the voice client.
Methods
getDbVolume()
The current playback volume expressed in decibels.
public
getDbVolume() : float|int
Maps the 0-100 linear volume to roughly -100 dB (mute) up to 0 dB (full).
Return values
float|intpause()
Pauses the current sound.
public
pause() : void
Tags
playDCAStream()
Plays a DCA stream.
public
playDCAStream(resource|Process|ReadableResourceStream $stream) : PromiseInterface
DCA is now deprecated in DiscordPHP, switch to using
playOggStream with raw Ogg Opus.
Parameters
- $stream : resource|Process|ReadableResourceStream
-
The DCA stream to be sent.
Tags
Return values
PromiseInterfaceplayFile()
Plays a file/url on the voice stream.
public
playFile(string $file[, int $channels = 2 ]) : PromiseInterface
FFmpeg is used to decode the file, so any format ffmpeg supports is accepted (e.g. WAV, OGG Opus, MP3, FLAC). Raw PCM files (.pcm) are NOT supported here because ffmpeg cannot auto-detect the format — use playPcmFile() instead.
Parameters
- $file : string
-
The file/url to play.
- $channels : int = 2
-
Deprecated, Discord only supports 2 channels.
Tags
Return values
PromiseInterfaceplayOggStream()
public
playOggStream(resource|Process|ReadableResourceStream $stream) : PromiseInterface
Parameters
- $stream : resource|Process|ReadableResourceStream
-
The Ogg Opus stream to be sent.
Tags
Return values
PromiseInterfaceplayPcmFile()
Plays a raw PCM file on the voice stream.
public
playPcmFile(string $path[, int $channels = 2 ][, int $audioRate = 48000 ]) : PromiseInterface
This is a convenience wrapper around playRawStream() for files saved as raw signed 16-bit little-endian PCM (e.g. recordings produced by record() with RecordingFormat::PCM).
Parameters
- $path : string
-
Absolute or relative path to the raw PCM file.
- $channels : int = 2
-
Number of audio channels (default: 2 = stereo).
- $audioRate : int = 48000
-
Sample rate in Hz (default: 48000).
Tags
Return values
PromiseInterfaceplayRawStream()
Plays a raw PCM16 stream.
public
playRawStream(resource|ReadableResourceStream $stream[, int $channels = 2 ][, int $audioRate = 48000 ]) : PromiseInterface
Parameters
- $stream : resource|ReadableResourceStream
-
The stream to be encoded and sent.
- $channels : int = 2
-
How many audio channels the PCM16 was encoded with.
- $audioRate : int = 48000
-
Audio sampling rate the PCM16 was encoded with.
Tags
Return values
PromiseInterfacesetAudioApplication()
Sets the audio application.
public
setAudioApplication(string $app) : void
Parameters
- $app : string
-
The audio application to set.
Tags
setBitrate()
Sets the bitrate.
public
setBitrate(int $bitrate) : void
Parameters
- $bitrate : int
-
The bitrate to set.
Tags
setSpeaking()
Sets the speaking value of the client.
public
setSpeaking([int $speaking = self::MICROPHONE ]) : void
Parameters
- $speaking : int = self::MICROPHONE
-
Whether the client is speaking or not.
Tags
setVolume()
Sets the volume.
public
setVolume(int $volume) : void
Parameters
- $volume : int
-
The volume to set.
Tags
stop()
Stops the current sound.
public
stop() : void
Tags
unpause()
Unpauses the current sound.
public
unpause() : void
Tags
readDCAOpus()
Reads and processes a single Opus audio frame from a DCA (Discord Compressed Audio) stream.
protected
readDCAOpus(Deferred $deferred) : void
Parameters
- $deferred : Deferred
-
A promise that will be resolved when the reading process completes or fails.
readOggOpus()
Reads Ogg Opus packets and sends them to the voice server.
protected
readOggOpus(Deferred $deferred, OggStream &$ogg, int &$loops) : void
Parameters
- $deferred : Deferred
-
The deferred promise.
- $ogg : OggStream
-
The Ogg stream to read packets from.
- $loops : int
-
The number of loops that have been executed.
reset()
Resets the voice client.
protected
reset() : void