Registry / serialization / opuslib

opuslib

JSON →
library3.0.1pypypi✓ verified 84d ago

Opuslib provides Python bindings to the `libopus` IETF low-delay audio codec. It allows Python applications to encode and decode Opus audio streams. The current version, 3.0.1, was released in January 2018. Note that this specific `opuslib` package is no longer actively maintained; users are encouraged to consider the `opuslib-next` fork for ongoing support and compatibility with newer Python versions.

pip install opuslib
INSTALL
IMPORT
SIG · OPUSLIB
O
opuslib
serializationpythonv3.0.1
Install
2.5s avg
Import
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v3.0.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 19.3MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 2.5s · import 0.000s · 20MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Encoder
from opuslib import Encoder
Decoder
from opuslib import Decoder
opuslib
import opuslib
import opus
The Python package is `opuslib`, not `opus`.

Demonstrates initializing an Opus encoder and decoder, then encoding a block of dummy PCM audio data and decoding it back. Remember to adjust `pcm_data_in` with actual audio samples for real-world use cases.

import opuslib # Encoder parameters SAMPLE_RATE = 48000 # Hz CHANNELS = 1 APPLICATION = opuslib.APPLICATION_AUDIO FRAME_SIZE_MS = 20 # milliseconds FRAME_SIZE_SAMPLES = int(SAMPLE_RATE * FRAME_SIZE_MS / 1000) # Create an encoder instance encoder = opuslib.Encoder(SAMPLE_RATE, CHANNELS, APPLICATION) # Example PCM audio data (replace with actual audio) pcm_data_in = b'\x00' * FRAME_SIZE_SAMPLES * 2 * CHANNELS # 16-bit mono, silent # Encode the audio encoded_data = encoder.encode(pcm_data_in, FRAME_SIZE_SAMPLES) print(f"Encoded {len(pcm_data_in)} bytes of PCM into {len(encoded_data)} bytes of Opus.") # Create a decoder instance decoder = opuslib.Decoder(SAMPLE_RATE, CHANNELS) # Decode the audio decoded_data = decoder.decode(encoded_data, FRAME_SIZE_SAMPLES) print(f"Decoded {len(encoded_data)} bytes of Opus into {len(decoded_data)} bytes of PCM.") # It's good practice to free resources if not using context managers (though opuslib handles it) del encoder del decoder
Debug
Known issues
breakingThe original `opuslib` package (version 3.0.1 and prior) is no longer actively maintained. For ongoing development, bug fixes, and compatibility with newer Python versions (e.g., Python 3.10+), it is highly recommended to use the `opuslib-next` fork.
fix
Use `pip install opuslib-next` and `import opuslib_next as opuslib` or directly `import opuslib_next`.
affects: <=3.0.1
gotchaOpuslib is a Python binding to the `libopus` C library. Installing the Python package (`pip install opuslib`) is not sufficient; the underlying `libopus` shared library must be installed on your system.
fix
Install `libopus` via your system's package manager (e.g., `sudo apt-get install libopus-dev` on Debian/Ubuntu, `brew install opus` on macOS).
affects: All versions
gotchaWhen decoding Ogg Opus files, you should not pass the Ogg 'OpusHead' or 'OpusTags' header packets directly to the `opuslib.Decoder.decode` method. The decoder expects raw Opus audio data packets.
fix
Ensure you are extracting actual Opus data packets from the Ogg container and skipping initial header packets before feeding them to the `decode` method.
affects: All versions
Errors
Common errors & fixes
Exception: Could not find opus library. Make sure it is installed.
The Python `opuslib` package was installed, but the underlying C library `libopus` is missing from the system.
fix
Install `libopus` using your operating system's package manager (e.g., `sudo apt-get install libopus-dev` or `brew install opus`).
OSError: dlopen(opus, 6): image not found
Similar to the 'Could not find opus library' error, this indicates that the Python bindings cannot locate the `libopus` shared library on your system's dynamic linker path.
fix
Ensure `libopus` is correctly installed (e.g., `sudo apt-get install libopus-dev`, `brew install opus`) and that its installation path is included in your system's library search paths (e.g., `LD_LIBRARY_PATH` on Linux, `DYLD_LIBRARY_PATH` on macOS, or proper system-wide installation).
opuslib.exceptions.OpusError: An audio packet failed to decode properly.
Often occurs when passing malformed data, non-Opus data, or Opus header packets to the decoder. It can also indicate incorrect decoder initialization parameters (sample rate, channels) that don't match the encoded stream.
fix
Verify that the input to `decoder.decode()` is a valid Opus audio data packet. Ensure the `Decoder` was initialized with the correct `fs` (sample rate) and `channels` matching the original encoding. Review data extraction from containers to ensure only audio data is passed.
Upgrade
Version history
3.0.1latest on PyPI · released Jan 16, 2018
Audit
Dependencies
libopusrequiredOpuslib is a binding to the C library `libopus`. This must be installed separately on your system.
Agent activity
30 hits · last 30 days
node
26
Resources