PHPackages                             discord-php-helpers/voice - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. discord-php-helpers/voice

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

discord-php-helpers/voice
=========================

A voice library for DiscordPHP

v8.1.1(2w ago)330.4k—8.4%31MITPHPPHP ^8.3CI passing

Since Dec 8Pushed 2w agoCompare

[ Source](https://github.com/discord-php/DiscordPHP-Voice)[ Packagist](https://packagist.org/packages/discord-php-helpers/voice)[ GitHub Sponsors](https://github.com/Log1x)[ GitHub Sponsors](https://github.com/valzargaming)[ RSS](/packages/discord-php-helpers-voice/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (9)Dependencies (7)Versions (13)Used By (1)

DiscordPHP Voice
================

[](#discordphp-voice)

[![Latest Stable Version](https://camo.githubusercontent.com/cf8c36871d3f6c0f0336c636504ebe9b0893c78f599fc00dc90ec4811055f92f/687474703a2f2f706f7365722e707567782e6f72672f646973636f72642d7068702d68656c706572732f766f6963652f76)](https://packagist.org/packages/discord-php-helpers/voice) [![Total Downloads](https://camo.githubusercontent.com/f7f16d37321c296105fdf4cbcdeb87dadaa046c93295704d7da3d59fb2c63681/687474703a2f2f706f7365722e707567782e6f72672f646973636f72642d7068702d68656c706572732f766f6963652f646f776e6c6f616473)](https://packagist.org/packages/discord-php-helpers/voice) [![Latest Unstable Version](https://camo.githubusercontent.com/364351959d97fc9bf5edab8034e095bee21a4dd9770ae2617a1aa89855c22aff/687474703a2f2f706f7365722e707567782e6f72672f646973636f72642d7068702d68656c706572732f766f6963652f762f756e737461626c65)](https://packagist.org/packages/discord-php-helpers/voice) [![License](https://camo.githubusercontent.com/5328b6291a90597180aaffcd9baaef1fc236dcf38a278d97de522117952aa8b6/687474703a2f2f706f7365722e707567782e6f72672f646973636f72642d7068702d68656c706572732f766f6963652f6c6963656e7365)](https://packagist.org/packages/discord-php-helpers/voice) [![PHP Version Require](https://camo.githubusercontent.com/8691916f19e7dd0bf3c8219a01e64ef1207a4cb3aa771af03856a73cb879e676/687474703a2f2f706f7365722e707567782e6f72672f646973636f72642d7068702d68656c706572732f766f6963652f726571756972652f706870)](https://packagist.org/packages/discord-php-helpers/voice) [![codecov](https://camo.githubusercontent.com/aedd915ea228d1a0d32569b18b262d0fb99b9e9b02bc6c9e7d1d8eb46c167091/68747470733a2f2f636f6465636f762e696f2f67682f646973636f72642d7068702f446973636f72645048502d566f6963652f67726170682f62616467652e737667)](https://codecov.io/gh/discord-php/DiscordPHP-Voice)

[![PHP Discorders](https://camo.githubusercontent.com/97ab4452b7e778d2ea1f8784d762a97a4472d5e5bdb391d45d213f4b863ce4be/68747470733a2f2f646973636f72642e636f6d2f6170692f6775696c64732f3131353233333131313937373039393237312f7769646765742e706e673f7374796c653d62616e6e657231)](https://discord.gg/dphp)

Getting Started
---------------

[](#getting-started)

Before you start using this Library, you **need** to know how PHP works, you need to know how Event Loops and Promises work. This is a fundamental requirement before you start. Without this knowledge, you will only suffer.

### Requirements

[](#requirements)

- [DiscordPHP](https://github.com/discord-php/DiscordPHP/)
- [PHP 8.3](https://php.net) or higher (latest version recommended)
    - x86 (32-bit) PHP requires [`ext-gmp`](https://www.php.net/manual/en/book.gmp.php) enabled.
- [`ext-json`](https://www.php.net/manual/en/book.json.php)

### DAVE (Discord Audio/Video End-to-End Encryption) runtime support

[](#dave-discord-audiovideo-end-to-end-encryption-runtime-support)

- **[📊 Visual DAVE Protocol Guide →](docs/DAVE.md)** — Mermaid diagrams covering architecture, MLS lifecycle, media encryption pipeline, and all DAVE opcodes.
- **[🎵 Audio Pipeline Guide →](docs/AUDIO_PIPELINE.md)** — Mermaid diagrams covering outbound/inbound audio flow, playback state machine, and format chain.
- **[📡 Protocol Reference →](docs/PROTOCOL.md)** — Voice gateway opcodes, DAVE opcodes, and close codes reference table.
- DAVE protocol negotiation is now supported at the voice gateway layer.
- Binary DAVE voice opcodes are parsed and routed.
- **Required:** [`ext-ffi`](https://www.php.net/manual/en/book.ffi.php) must be enabled and `libdave` must be available — the runtime loads libdave session and media APIs and detects the maximum supported DAVE protocol version.
- Use `./scripts/setup-libdave.sh` to fetch the published `discord/libdave` release asset into `.cache/libdave` without vendoring the binary into git. The script auto-detects your OS and architecture (Linux, macOS, Windows — x64 and ARM64).
- Export `DISCORDPHP_DAVE_LIBRARY` pointing to the platform library (e.g. `.cache/libdave/lib/libdave.so` on Linux) to force the runtime to use the repo-local shared library path.
- CI uses the same setup script and enables `ext-ffi` so native DAVE coverage stays runnable.
- libdave is **required** for voice connections. `Manager::__construct()` and the voice WebSocket throw `LibDaveNotFoundException` immediately when [`ext-ffi`](https://www.php.net/manual/en/book.ffi.php) or a working libdave library cannot be loaded — there is currently no automatic fallback to protocol version `0`. Discord has required the DAVE E2EE protocol for all voice and video connections since March 1st, 2026.

#### Local setup

[](#local-setup)

```
COMPOSER_ROOT_VERSION=dev-main composer install --no-interaction --prefer-dist
./scripts/setup-libdave.sh

# Linux
export DISCORDPHP_DAVE_LIBRARY="$PWD/.cache/libdave/lib/libdave.so"
# macOS
# export DISCORDPHP_DAVE_LIBRARY="$PWD/.cache/libdave/lib/libdave.dylib"
# Windows (Git Bash / PowerShell)
# export DISCORDPHP_DAVE_LIBRARY="$PWD/.cache/libdave/bin/libdave.dll"

./vendor/bin/pest tests/Unit/Dave/RuntimeTest.php
```

The script auto-detects your OS and architecture (Linux, macOS, Windows — x64 and ARM64). Set `DISCORDPHP_DAVE_LIBRARY` to the path printed by the script. Use the bundled Pest runner for local validation. `composer unit` runs the default suite with TestDox output, while `composer pest` keeps the parallel full-suite command.

Composer Scripts
----------------

[](#composer-scripts)

ScriptDescription`composer unit`Run the test suite (`pest --testdox`)`composer lint`Run PHPLint syntax check`composer check`Run CS-Fixer dry-run + PHPLint + tests (CI-safe, no rewrites)`composer cs`Auto-format with PHP-CS-Fixer (rewrites files)`composer cs:check`Check style without rewriting files`composer phpstan`Run static analysis (level 5)`composer infection`Run mutation testing (slow — local only)`composer coverage`Run tests with Xdebug coverage report### Basic Example

[](#basic-example)

```
$discord->on('init', function (Discord $discord) {
    $channel = $discord->getChannel('YOUR_CHANNEL_ID');

    $discord->voice->joinChannel($channel)->then(function (VoiceClient $vc) {
        $vc->on('ready', function () use ($vc) {
            $vc->playFile('/path/to/audio.mp3');
        });

        $vc->on('end', function () use ($vc) {
            $vc->disconnect();
        });
    });
});
```

### Recording

[](#recording)

```
// Raw PCM events — handle audio yourself
$discord->voice->joinChannel($channel)->then(function (VoiceClient $vc) use ($discord) {
    $vc->on('ready', function () use ($vc, $discord) {
        $vc->record();

        // Fires with raw 16-bit stereo 48 kHz PCM for each decoded Opus frame.
        $vc->on('channel-pcm', function (string $pcm) {
            // write $pcm to a file, pipe to an encoder, etc.
        });

        $discord->getLoop()->addTimer(10, function () use ($vc) {
            $vc->stopRecording();
            $vc->disconnect();
        });
    });
});
```

```
use Discord\Voice\Recording\RecordingFormat;

// Automatic per-user WAV files — no manual file handling needed
$discord->voice->joinChannel($channel)->then(function (VoiceClient $vc) use ($discord) {
    $vc->on('ready', function () use ($vc, $discord) {
        $vc->record(
            RecordingFormat::WAV,
            fn(string $userId) => "/tmp/recording_{$userId}.wav"
        );

        $discord->getLoop()->addTimer(10, function () use ($vc) {
            $vc->stopRecording(); // finalizes and closes all WAV files
            $vc->disconnect();
        });
    });
});
```

> **Recording formats:** `RecordingFormat::PCM` emits raw PCM events (default). `RecordingFormat::WAV` writes self-contained WAV files per user (pure PHP). `RecordingFormat::OGG` writes OGG Opus files per user (requires ffmpeg).

See [examples folder](examples) for full runnable scripts.

Documentation
-------------

[](#documentation)

Documentation for the latest version can be found [here](//discord-php.github.io/DiscordPHP/guide). Community contributed tutorials can be found on the [wiki](//github.com/discord-php/DiscordPHP/wiki).

Troubleshooting
---------------

[](#troubleshooting)

Having issues? See [**docs/TROUBLESHOOTING.md**](docs/TROUBLESHOOTING.md) for solutions to common problems including missing libraries (libdave, ffmpeg, opus, libsodium), permission errors, and playback state issues.

Exceptions
----------

[](#exceptions)

All library exceptions implement the [`VoiceException`](src/Discord/Voice/Exceptions/VoiceException.php) marker interface, so you can catch any voice error with a single handler:

```
use Discord\Voice\Exceptions\VoiceException;

try {
    $manager->joinChannel($channel);
} catch (VoiceException $e) {
    echo "Voice error: " . $e->getMessage();
}
```

Common exceptions include `LibDaveNotFoundException`, `EnterChannelDeniedException`, `CantSpeakInChannelException`, `FFmpegNotFoundException`, and `LibSodiumNotFoundException`.

Contributing
------------

[](#contributing)

We are open to contributions. However, please make sure you follow our coding standards (PSR-4 autoloading and custom styling). Please run php-cs-fixer before opening a pull request by running `composer cs`.

See [CONTRIBUTING.md](CONTRIBUTING.md) for setup, coding standards, and PR guidelines.

See [CHANGELOG.md](CHANGELOG.md) for version history.

License
-------

[](#license)

MIT License, © David Cole and other contributors 2016-present.

###  Health Score

54

—

FairBetter than 96% of packages

Maintenance96

Actively maintained with recent releases

Popularity35

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~19 days

Recently: every ~38 days

Total

11

Last Release

14d ago

PHP version history (2 changes)v8.0.0PHP ^8.1.2

v8.0.0-beta1PHP ^8.3

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7202504?v=4)[Valithor Obsidion](/maintainers/valzargaming)[@valzargaming](https://github.com/valzargaming)

---

Top Contributors

[![alexandre433](https://avatars.githubusercontent.com/u/10622522?v=4)](https://github.com/alexandre433 "alexandre433 (120 commits)")[![valzargaming](https://avatars.githubusercontent.com/u/7202504?v=4)](https://github.com/valzargaming "valzargaming (117 commits)")[![Copilot](https://avatars.githubusercontent.com/in/1143301?v=4)](https://github.com/Copilot "Copilot (7 commits)")[![bwoebi](https://avatars.githubusercontent.com/u/3154871?v=4)](https://github.com/bwoebi "bwoebi (1 commits)")

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/discord-php-helpers-voice/health.svg)

```
[![Health](https://phpackages.com/badges/discord-php-helpers-voice/health.svg)](https://phpackages.com/packages/discord-php-helpers-voice)
```

###  Alternatives

[phpwhois/phpwhois

phpWhois - library for querying whois services and parsing results. Based on phpwhois.org

321393.9k1](/packages/phpwhois-phpwhois)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
