Skip to main content

Library to replace the voice backend of discord.py with Songbird.

Project description

discord-ext-songbird

GitHub License GitHub Release PyPI - Version PyPI - Python Version

High-performance voice backend for discord.py, powered by Songbird and written in Rust.

discord-ext-songbird provides a native VoiceProtocol implementation for discord.py, exposing Songbird's Rust audio pipeline through PyO3.

Highlights

  • Drop-in VoiceProtocol via SongbirdClient
  • Low-latency playback backed by Songbird
  • Voice receive APIs (BufferSink, StreamSink)
  • Native input types for raw PCM, encoded audio, and streaming
  • PyO3/maturin extension with CPython 3.14 and free-threaded CPython 3.14 support
  • Beta release series (API may evolve)

Installation

pip install discord-ext-songbird
uv add discord-ext-songbird

Quickstart

import pyarrow as pa
import discord
from discord.ext import songbird
from discord.ext.songbird import player

client = discord.Client(intents=discord.Intents.default())

@client.event
async def on_ready():
    channel = client.get_channel(int(CHANNEL_ID))
    if isinstance(channel, discord.VoiceChannel):
        vc = await channel.connect(cls=songbird.SongbirdClient)

        samples = pa.array([0.0, 0.1, 0.0, -0.1], type=pa.float32())
        source = player.RawPCMInput(samples, sample_rate=48000, channels=2)
        track = player.Track(source).volume(0.8)
        await vc.play(track)

client.run(DISCORD_BOT_TOKEN)

Features

Detailed API guides are available for voice output and voice receive.

Playback

Use SongbirdClient as your voice client. Playback is driven by Track and TrackHandle.

from discord.ext import songbird
from discord.ext.songbird import player

vc = await channel.connect(cls=songbird.SongbirdClient)
track = player.Track(source)
handle = await vc.play(track)
handle.pause()

Inputs

Native input types are exported from discord.ext.songbird.player.

  • RawPCMInput: pyarrow.Float32Array PCM input
  • AudioInput: encoded audio in a pyarrow.Array
  • StreamInput: asyncio.StreamReader
  • OpusPacketInput: pre-encoded 20 ms Opus frames in a pyarrow.BinaryArray
  • OpusPacketStreamInput: live pre-encoded 20 ms Opus packet stream

AudioInput and StreamInput no longer take a codec argument. Songbird 0.6 detects encoded stream formats internally, so SupportedCodec has been removed from the Python API. For Ogg/WebM/DCA Opus sources, Songbird may use Opus passthrough internally. For raw Opus packets, use OpusPacketInput or OpusPacketStreamInput. Passthrough requires a single active track, 20 ms Opus frames, and volume 1.0.

import asyncio
from discord.ext.songbird import player

buffer = asyncio.StreamReader()
source = player.StreamInput(buffer)
track = player.Track(source)
import pyarrow as pa
from discord.ext.songbird import player

frames = pa.array([opus_frame_0, opus_frame_1], type=pa.binary())
source = player.OpusPacketInput(frames)
track = player.Track(source)  # keep volume at 1.0 for passthrough

Voice receive

Receive decoded PCM via BufferSink or StreamSink.

from discord.ext.songbird import receive

sink = receive.BufferSink(max_duration_secs=5)
vc.listen(sink)

async for batch in sink:
    # batch is a pyarrow.RecordBatch with key_kind, key_id, speaking, and pcm columns
    handle_batch(batch)

async for pcm in sink[receive.VoiceKey.User(user_id)]:
    if pcm is not None:
        handle_pcm(pcm)

Receive iteration is columnar. The pcm column is list<int16> and stores all speaking users for a tick in one shared Arrow buffer. Per-key convenience iteration still returns pyarrow.Int16Array | None. SSRC to user ID mapping is tracked at the voice connection level from Songbird's speaking updates, so VoiceKey.Unknown(ssrc) is limited to packets seen before Discord has exposed that mapping.

Examples

See examples/ for runnable bots:

  • examples/basic.py (PCM playback)
  • examples/send_stream.py (stream input)
  • examples/receive_stream.py (voice receive)

For deeper usage notes, see Send (Voice Output) and Receive (Voice Input).

Set DISCORD_BOT_TOKEN and CHANNEL_ID before running the examples.

Requirements

  • Python 3.14+
  • discord.py
  • pyarrow

Published CPython wheels are split by ABI. The release workflow builds regular cp314 wheels and free-threaded cp314t wheels for the supported platforms, so a normal Python 3.14 environment installs the regular wheel while Python 3.14t installs the free-threaded wheel. Published wheels are built with the full Symphonia codec/format set enabled. Rust codec features are compile-time options, so installed wheels cannot switch codec sets at runtime. For a smaller source build, pass Cargo features through Maturin:

pip install . --config-settings="maturin.build-args=--no-default-features --features codec-minimal"

Development

uv sync --all-extras --dev --no-install-project --python 3.14t
uv run maturin develop

The default local environment uses free-threaded CPython 3.14 (3.14t). Release wheels are built separately for the normal and free-threaded ABIs (cp314 and cp314t). To check the normal 3.14 build locally, point PyO3 at a GIL-enabled interpreter:

PYO3_PYTHON=/path/to/python3.14 cargo check
just build
just fmt
just check

Contributing

Issues and pull requests are welcome. Please keep changes focused and avoid committing build artifacts.

License

MIT. See LICENSE.

Acknowledgements

  • Songbird (Rust voice library)
  • discord.py (Python Discord API wrapper)
  • PyO3 (Rust bindings for Python)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

discord_ext_songbird-0.5.0.tar.gz (122.5 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

discord_ext_songbird-0.5.0-cp314-cp314t-win_amd64.whl (5.0 MB view details)

Uploaded CPython 3.14tWindows x86-64

discord_ext_songbird-0.5.0-cp314-cp314t-win32.whl (4.2 MB view details)

Uploaded CPython 3.14tWindows x86

discord_ext_songbird-0.5.0-cp314-cp314t-musllinux_1_2_x86_64.whl (5.7 MB view details)

Uploaded CPython 3.14tmusllinux: musl 1.2+ x86-64

discord_ext_songbird-0.5.0-cp314-cp314t-musllinux_1_2_aarch64.whl (5.2 MB view details)

Uploaded CPython 3.14tmusllinux: musl 1.2+ ARM64

discord_ext_songbird-0.5.0-cp314-cp314t-manylinux_2_28_x86_64.whl (5.4 MB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.28+ x86-64

discord_ext_songbird-0.5.0-cp314-cp314t-manylinux_2_28_aarch64.whl (5.1 MB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.28+ ARM64

discord_ext_songbird-0.5.0-cp314-cp314t-macosx_11_0_arm64.whl (4.7 MB view details)

Uploaded CPython 3.14tmacOS 11.0+ ARM64

discord_ext_songbird-0.5.0-cp314-cp314-win_amd64.whl (5.1 MB view details)

Uploaded CPython 3.14Windows x86-64

discord_ext_songbird-0.5.0-cp314-cp314-win32.whl (4.2 MB view details)

Uploaded CPython 3.14Windows x86

discord_ext_songbird-0.5.0-cp314-cp314-musllinux_1_2_x86_64.whl (5.7 MB view details)

Uploaded CPython 3.14musllinux: musl 1.2+ x86-64

discord_ext_songbird-0.5.0-cp314-cp314-musllinux_1_2_aarch64.whl (5.2 MB view details)

Uploaded CPython 3.14musllinux: musl 1.2+ ARM64

discord_ext_songbird-0.5.0-cp314-cp314-manylinux_2_28_x86_64.whl (5.4 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.28+ x86-64

discord_ext_songbird-0.5.0-cp314-cp314-manylinux_2_28_aarch64.whl (5.1 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.28+ ARM64

discord_ext_songbird-0.5.0-cp314-cp314-macosx_11_0_arm64.whl (4.7 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

File details

Details for the file discord_ext_songbird-0.5.0.tar.gz.

File metadata

  • Download URL: discord_ext_songbird-0.5.0.tar.gz
  • Upload date:
  • Size: 122.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.13.3

File hashes

Hashes for discord_ext_songbird-0.5.0.tar.gz
Algorithm Hash digest
SHA256 1df33b81bc80828343fcaef80dee1fb628f5aa0f3f29f8851f91c4e0c058b2d2
MD5 6b9c22cb8e8acb07ee77f4fbd16afd6f
BLAKE2b-256 fee115781b0e44e024597b66b039822ca715748e0548381c6941596db6167e89

See more details on using hashes here.

File details

Details for the file discord_ext_songbird-0.5.0-cp314-cp314t-win_amd64.whl.

File metadata

File hashes

Hashes for discord_ext_songbird-0.5.0-cp314-cp314t-win_amd64.whl
Algorithm Hash digest
SHA256 da59969d1d097933468955fbc4205d8949240bba85704dce6c1f11be82c275a4
MD5 20c2ecf655453b58c52642ce9bca5f03
BLAKE2b-256 74cb5de40e0b3fb70923849304b7ffca7f6f3a79a878dfab9ad645c496408d63

See more details on using hashes here.

File details

Details for the file discord_ext_songbird-0.5.0-cp314-cp314t-win32.whl.

File metadata

File hashes

Hashes for discord_ext_songbird-0.5.0-cp314-cp314t-win32.whl
Algorithm Hash digest
SHA256 bd64f7a933dae7b4e494a580a4dab85eb409afc25a6257b68bf8411826c7af9c
MD5 c7bf364515778f17605b39e07cb9b073
BLAKE2b-256 08fc4b72dbcbffa07fca712b8b1ea0ac37b85a1a5e6032dde4a784ace66a931a

See more details on using hashes here.

File details

Details for the file discord_ext_songbird-0.5.0-cp314-cp314t-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for discord_ext_songbird-0.5.0-cp314-cp314t-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 df88eca550b25b6c8f6ba44b741d6f4e0a6864ea8bd77bf699947e9b007c66a0
MD5 2253707edfcaec368b782f5d90cc82b1
BLAKE2b-256 1018cffb3a80bcbb9ca95623a26f3672be3c7501e7a433ced737ef1a3b4c4f9f

See more details on using hashes here.

File details

Details for the file discord_ext_songbird-0.5.0-cp314-cp314t-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for discord_ext_songbird-0.5.0-cp314-cp314t-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 16c7ee49aab23a2e9092101ea64c1aaf2e362275e4c90fbd35a07039af862e64
MD5 9b2d85c2eff42f2785d67c55d18c843f
BLAKE2b-256 0b6af66708d5bfbc73550b49d176df7cf7cae4962aa9a1cb90ce752a41619986

See more details on using hashes here.

File details

Details for the file discord_ext_songbird-0.5.0-cp314-cp314t-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for discord_ext_songbird-0.5.0-cp314-cp314t-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d000ee08b064a91d25f86cc7339c631d6acfb9e5630fa6197f089d439e76cf02
MD5 e7f1a406bbe615add87dd0e3180dfbd6
BLAKE2b-256 f429d85118e191f7c9d646fc754f0c3ca99f9a00cf53c7f533e0fee59a83b301

See more details on using hashes here.

File details

Details for the file discord_ext_songbird-0.5.0-cp314-cp314t-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for discord_ext_songbird-0.5.0-cp314-cp314t-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 f17d5970b49efbc54b9310bd5005d30e70cc89c2e03b7c17610c70fe48a90c21
MD5 a970d26c7afe2919f5ef5d6e1fb729fc
BLAKE2b-256 11987142ace92922cc20975f7006b42243a6a29679c8061295feb968dfcd4928

See more details on using hashes here.

File details

Details for the file discord_ext_songbird-0.5.0-cp314-cp314t-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for discord_ext_songbird-0.5.0-cp314-cp314t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b125d6efbe6b8c9dc4d495d9e8435785f2c29edcfcde8f0e9e405e1bc55d38d7
MD5 bbda04b987425c9741dbdc7fe33608ee
BLAKE2b-256 76f6f62c0e53fd53fdf4dd2a6ebf92e6c6766c45eb6d4b7f8df3fc7987121f60

See more details on using hashes here.

File details

Details for the file discord_ext_songbird-0.5.0-cp314-cp314-win_amd64.whl.

File metadata

File hashes

Hashes for discord_ext_songbird-0.5.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 dc18dcb1c1e8144c8e5960242659e28940a826a1279933b3c24a329fca0044ce
MD5 e97c6834ae7183740a501f6229a4f7c1
BLAKE2b-256 10f01eb58c502fbc1b76a36d31f6f5b0ab617116ffc6526be1759d53d5375fe9

See more details on using hashes here.

File details

Details for the file discord_ext_songbird-0.5.0-cp314-cp314-win32.whl.

File metadata

File hashes

Hashes for discord_ext_songbird-0.5.0-cp314-cp314-win32.whl
Algorithm Hash digest
SHA256 d08f9d4a3d9cbdff18ff4368a5a841463db27aa0d5ee29a472359e8f5a51aa73
MD5 1484180fed3a99ee090de0adc7912903
BLAKE2b-256 5028d07f16d829a58baa8bdc2a33c5768b692770befae4f17abae8abcc1c09ef

See more details on using hashes here.

File details

Details for the file discord_ext_songbird-0.5.0-cp314-cp314-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for discord_ext_songbird-0.5.0-cp314-cp314-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 263861d5c742347d0d2c106dcab94ccc17910c125f738fb4484ab71812d41b89
MD5 ea0bc0a87d4c6d1cd0f89888759d32e0
BLAKE2b-256 bad2d2c1c64c05794316271db4a2159aaec90c262ffb74aa19c09ab843cd0c83

See more details on using hashes here.

File details

Details for the file discord_ext_songbird-0.5.0-cp314-cp314-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for discord_ext_songbird-0.5.0-cp314-cp314-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 8cb428f1671d9c5a2657cc7af72bfd30794787de6c13295a350de6bfa13bc0d8
MD5 5fda656e9ea02871643365b3a1ab8f00
BLAKE2b-256 19eeb8f034f17b772333131855608096943fe42f64a8bd24eda7e87736f7fedf

See more details on using hashes here.

File details

Details for the file discord_ext_songbird-0.5.0-cp314-cp314-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for discord_ext_songbird-0.5.0-cp314-cp314-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5a5d27a3240f2835edf1ddec5e8c5d2324d82df7062b85b51fd30c4de1be4620
MD5 2027bc1ae2f076acff66127a0c7a1f10
BLAKE2b-256 eb3573fde8f0435458f0c558f199df6f3495092e2bc3c93b888b3e7348b4704b

See more details on using hashes here.

File details

Details for the file discord_ext_songbird-0.5.0-cp314-cp314-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for discord_ext_songbird-0.5.0-cp314-cp314-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 cb0cae4c0c69051d15544dabaa05b709fd1e153ce0a74f434f241138326a7bc8
MD5 0660325673dca13bc309241b5553ddb4
BLAKE2b-256 f73cb3cbb36f4783c3346cb826dd04204d85fb52678a500178dc2f52584fbfdc

See more details on using hashes here.

File details

Details for the file discord_ext_songbird-0.5.0-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for discord_ext_songbird-0.5.0-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 11d43d2788c6f3627bcc0fb3dbd5d4e1d8fbcdd7a5fcb94f1b91d9f82b602983
MD5 f96c54b2bc851d70330361752a0f5691
BLAKE2b-256 a55c31b2b301d3a5c71e2afcc7d89d3c8246911fd3a939fd81a774bd577a693c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page