Skip to main content

Python bindings and self-contained Opus CLI builds with QEXT enabled by default.

Project description

opuscodec

Python bindings and self-contained Opus CLI builds, with QEXT enabled by default.

opuscodec packages three things together:

  • OpusBufferedEncoder / OpusBufferedDecoder Python bindings
  • self-contained opusenc / opusdec release binaries
  • vendored Xiph dependencies, built from source when needed

Stable dependency set:

  • opus 1.6.1
  • opus-tools 0.2
  • libogg 1.3.6
  • opusfile 0.12
  • libopusenc 0.3

Why this package

  • no system Opus install required by default
  • runtime + build-time QEXT control
  • Python API and CLI assets released from one repo
  • PyPI wheels for supported targets, source build fallback everywhere else

Installation

PyPI (recommended)

python -m pip install opuscodec==0.1.2

GitHub Release asset

python -m pip install "https://github.com/fishaudio/opuscodec/releases/download/v0.1.2/<wheel-file-name>.whl"

Example Linux wheel name:

python -m pip install ./opuscodec-0.1.2-cp312-cp312-manylinux_2_28_x86_64.whl

Source build

make test

Common commands:

make install    # editable install + test deps
make test       # run pytest
make wheel      # build wheel into dist/wheels
make binaries   # build opusenc/opusdec into dist/bin
make clean      # clean build artifacts

Python example

import numpy as np
import opuscodec

sr = 48000
x = (0.1 * np.sin(2 * np.pi * 440 * np.arange(sr) / sr) * 32767).astype(np.int16).reshape(-1, 1)

enc = opuscodec.OpusBufferedEncoder(sample_rate=sr, channels=1)
packet = enc.write(x) + enc.flush()

dec = opuscodec.OpusBufferedDecoder()
y = dec.decode(packet)

print(y.shape, opuscodec.opus_version(), opuscodec.qext_enabled(), enc.qext_enabled())

Disable runtime QEXT for one encoder instance:

enc = opuscodec.OpusBufferedEncoder(sample_rate=48000, channels=1, qext=False)

Standalone binary usage

After downloading release binaries:

tar -xzf opuscodec-v0.1.2-linux-amd64-binaries.tar.gz
chmod +x opusenc opusdec

WAV roundtrip

./opusenc input.wav output.opus
./opusdec output.opus roundtrip.wav

opusenc enables QEXT by default in this repository build. Disable it explicitly for comparison tests:

./opusenc --set-ctl-int 4056=0 input.wav output-noqext.opus

Raw PCM roundtrip

Encode raw PCM (mono, 48k, s16le) to Opus:

./opusenc --raw --raw-bits 16 --raw-rate 48000 --raw-chan 1 input.pcm output.opus

Decode Opus back to PCM:

./opusdec output.opus decoded.pcm

Build configuration

Defaults: vendored dependencies; QEXT enabled.

Optional environment variables:

  • OPUSCODEC_ENABLE_QEXT=0 — disable QEXT
  • OPUSCODEC_USE_SYSTEM_DEPS=1 — use system libraries instead of vendored build
  • OPUSCODEC_DEPS_PREFIX=/path/to/prefix — custom dependency prefix

When QEXT is enabled at build time, packaged opusenc binaries also enable OPUS_SET_QEXT(1) by default.

Repository layout

.
├── .github/workflows/build.yml
├── Makefile
├── pyproject.toml
├── setup.py
├── src/
│   └── opuscodec_bindings.cpp
├── scripts/
│   ├── build_deps.sh
│   └── build_binaries.sh
├── tests/
│   └── test_bindings.py
├── opusenc.py
└── opusdec.py

Release automation

On tag push (for example v0.1.2), GitHub Actions will:

  • run tests on Linux + macOS
  • build PyPI-compatible manylinux wheels for Linux
  • build macOS arm64 wheels
  • build an sdist
  • publish wheel + sdist artifacts to PyPI via OIDC
  • create a GitHub Release and upload wheels + binary tarballs

License

Apache License 2.0. See LICENSE.

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

opuscodec-0.1.2.tar.gz (11.5 kB view details)

Uploaded Source

Built Distributions

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

opuscodec-0.1.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (456.0 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

opuscodec-0.1.2-cp312-cp312-macosx_11_0_universal2.whl (530.8 kB view details)

Uploaded CPython 3.12macOS 11.0+ universal2 (ARM64, x86-64)

opuscodec-0.1.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (453.9 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

opuscodec-0.1.2-cp311-cp311-macosx_11_0_universal2.whl (524.7 kB view details)

Uploaded CPython 3.11macOS 11.0+ universal2 (ARM64, x86-64)

File details

Details for the file opuscodec-0.1.2.tar.gz.

File metadata

  • Download URL: opuscodec-0.1.2.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for opuscodec-0.1.2.tar.gz
Algorithm Hash digest
SHA256 ed6d11cc7b340322bd28196813369ec6716163f0916b09296a6becee2e99b23f
MD5 2ce045595fac851080259ccd319265a6
BLAKE2b-256 f46158b7ae266f49d6d1ecdb34ce8ec246557a2aff300e89c1256ddd23b7c5c7

See more details on using hashes here.

Provenance

The following attestation bundles were made for opuscodec-0.1.2.tar.gz:

Publisher: build.yml on fishaudio/opuscodec

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file opuscodec-0.1.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for opuscodec-0.1.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c9aed87b65343cfdc430642b92dc0cde565c9ccc1c7831b3bedbaa2c4411c373
MD5 4c142841e253a936fc801201acb137c9
BLAKE2b-256 67ead1ecfacd669d7b039092b6747979bf41b586a3c407c670c4f49bde0f7340

See more details on using hashes here.

Provenance

The following attestation bundles were made for opuscodec-0.1.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build.yml on fishaudio/opuscodec

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file opuscodec-0.1.2-cp312-cp312-macosx_11_0_universal2.whl.

File metadata

File hashes

Hashes for opuscodec-0.1.2-cp312-cp312-macosx_11_0_universal2.whl
Algorithm Hash digest
SHA256 67db0c2f3b88919ca336c576571b4c3e8ba404daced209c0a3d05a39d574fe49
MD5 a79d74c0d1f71f9b0630094287e3646d
BLAKE2b-256 afe92fae0e96f2db16d8695fc80fd2b698fdd83c8b668680eaab3362f6a43422

See more details on using hashes here.

Provenance

The following attestation bundles were made for opuscodec-0.1.2-cp312-cp312-macosx_11_0_universal2.whl:

Publisher: build.yml on fishaudio/opuscodec

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file opuscodec-0.1.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for opuscodec-0.1.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 438e42f27f474c372d9f779058da8b45d68daa25a0e8c52a7bffa7604fc7fbca
MD5 733b431a9e97043f832387319b10e257
BLAKE2b-256 ab6e0764d0cbf4f08ad597934294831b25fbdddc61717c2068dace5b395de225

See more details on using hashes here.

Provenance

The following attestation bundles were made for opuscodec-0.1.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build.yml on fishaudio/opuscodec

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file opuscodec-0.1.2-cp311-cp311-macosx_11_0_universal2.whl.

File metadata

File hashes

Hashes for opuscodec-0.1.2-cp311-cp311-macosx_11_0_universal2.whl
Algorithm Hash digest
SHA256 eee5d359b6c92f6ed36dba3fa459b39370e760c4eacf687dac6d000d991c7127
MD5 3d3ad22f99585f16e8e4d2e23ce3e25d
BLAKE2b-256 a6420d3e7f7acaa1e8b7cf8baa988d4626a2c2d01c8706fa8aee559e36a367dd

See more details on using hashes here.

Provenance

The following attestation bundles were made for opuscodec-0.1.2-cp311-cp311-macosx_11_0_universal2.whl:

Publisher: build.yml on fishaudio/opuscodec

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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