DiscordPHP-Voice Documentation

ManagesRecording

Recording concern of {@see \Discord\Voice\VoiceClient}: {@see record()} / {@see stopRecording()} and the per-user file-sink lifecycle.

Tags
since
10.20.0

Table of Contents

Methods

record()  : void
Starts recording incoming voice audio.
stopRecording()  : void
Stops an in-progress recording started by {@see record()}.

Methods

record()

Starts recording incoming voice audio.

public record([RecordingFormat|null $format = null ][, callable(string): string|null $outputPath = null ]) : void

When called with no arguments, raw PCM and Opus frames are emitted via the channel-pcm and channel-opus events for the caller to handle.

When called with a format and output path callback, the voice client automatically writes per-user audio files. The callback receives the user ID string and must return an absolute or relative file path string.

Supported formats:

  • RecordingFormat::PCM — raw s16le PCM; emits channel-pcm events AND writes raw bytes to per-user files when $outputPath is provided
  • RecordingFormat::WAV — per-user WAV files via pure-PHP WavWriter
  • RecordingFormat::OGG — per-user OGG Opus files via ffmpeg (requires ffmpeg)
Parameters
$format : RecordingFormat|null = null

Output format. Null = PCM events only (no file writing).

$outputPath : callable(string): string|null = null

Callback returning the file path for a given user ID. Required for WAV and OGG formats. Optional for PCM (when provided, raw PCM bytes are written to the file).

Tags
throws
RuntimeException

if already recording.

InvalidArgumentException

if $format is non-null/non-PCM but $outputPath is null.

stopRecording()

Stops an in-progress recording started by {@see record()}.

public stopRecording() : void

Finalises every per-user writer, closes recording processes and PCM handles, and clears all receive-stream, decoder and speaking state.

Tags
throws
RuntimeException

if no recording is in progress.

On this page

Search results