g711xz - lossless storage for G.711 call recordings
Every call that crosses a phone network as PCMU or PCMA is already compressed: each 16-bit sample is one of at most 256 values. Store it as WAV and every second byte is redundant. Store it as MP3 or Opus and the codec quietly rewrites the audio, in ways a person barely hears and a speech recognizer does.
g711xz keeps the call exactly as it arrived. It turns the samples back into their 8-bit G.711 codes, packs them with xz, and gives back the original PCM bit for bit. Ringing and silence shrink to almost nothing; a conversation takes more space than Opus. It is a command line tool and a Python library for Linux, macOS, and Windows, with a Rust extension in the published wheels.
English | Spanish | Portuguese | French | German | Italian | Russian | Chinese | Japanese | Hindi
Requirements
- Python 3.9 or higher
- Linux, macOS, Windows: no platform-specific requirements
- Dependencies: none, the standard library is enough
- Optional: NumPy or the Rust extension, used as accelerators when present
File Format
One file is one recorded call: the left channel is the caller, the right channel is the callee.
- ✅ Lossless: decoding returns the recorder's 16-bit PCM bit for bit
- ✅ mu-law (PCMU) and A-law (PCMA)
- ✅ About a quarter smaller than xz on the raw PCM
- ✅ One standard xz stream, readable with
xzalone - ❌ Audio that is not pure G.711: refused instead of rounded
- ❌ Metadata: the file holds the audio and nothing else
How it compares
| PCM | xz | g711xz | Opus 32 kbit/s | MP3 32 kbit/s | |
|---|---|---|---|---|---|
| Decodes back to the original | yes | yes | yes | no | no |
| Words matching the original transcript, % | 100 | 100 | 100 | 94.9 | 94.4 |
| Calls with a word-for-word identical transcript, % | 100 | 100 | 100 | 71.9 | 65.7 |
| Average size, kbit/s | 256 | 28.6 | 21.8 | 20.8 | 32.4 |
| 5 minutes, MB | 9.60 | 1.07 | 0.82 | 0.78 | 1.22 |
| CPU to encode, relative to Opus | 0 | 0.43 | 0.23 | 1 | 0.16 |
- xz alone is lossless too, just bigger. It compresses the 16-bit samples, g711xz the 8-bit codes they were made from: xz comes out about 30% larger and takes twice the CPU.
- The recognizer is not to blame. The same audio transcribed twice agrees on 100% of the words and on 99.6% of the calls, so the gaps in the Opus and MP3 columns come from the codecs.
- Why a conversation is larger than Opus and MP3. They work to a bitrate and throw away whatever does not fit. g711xz keeps every sample, and in speech the low bits of each G.711 code carry line noise and fine detail that no lossless compressor can shrink. Ringing and silence work the other way: they compress to almost nothing, so across many calls g711xz ends up close to Opus and well below MP3.
Installation
pip3 install g711xz
Or from GitHub (this builds the Rust extension and needs a Rust toolchain and a C compiler):
pip3 install git+https://github.com/wachawo/g711xz.git
Usage
# Show the header, duration and bitrate of a file
g711xz info rec.g711.xz
# Decode to a lossless stereo WAV (writes rec.wav)
g711xz decode rec.g711.xz
# Decode to a chosen file
g711xz decode rec.g711.xz out.wav
# Encode a 2-channel 16-bit 8000 Hz WAV (writes rec.g711.xz)
g711xz encode rec.wav
# Convert to the other law, lossy (u = mu-law, a = A-law)
g711xz transcode rec.g711.xz a rec.alaw.g711.xz
# Show help
g711xz --help
Example output of g711xz info:
rec.g711.xz:
format CRG7 version 1
law mu-law (PCMU)
channels 2 (left caller, right callee)
rate 8000 Hz
frames 480000
duration 60.000 s
size 108316 bytes (14.4 kbit/s)
Python API
import g711xz
# Decode: law is b"u" or b"a", pcm is interleaved s16le stereo at 8000 Hz
law, frames, pcm = g711xz.decode("rec.g711.xz")
g711xz.write_wav("rec.wav", pcm)
# Encode: returns the bytes of a .g711.xz file
data = g711xz.encode(g711xz.read_wav("rec.wav"))
Encoding raises g711xz.RefusedError when the PCM is not pure G.711, and reading raises g711xz.FormatError for a damaged file.
Exit codes
| Code | Meaning |
|---|---|
| 0 | Success. |
| 2 | Bad input: a damaged or foreign file, a WAV of the wrong format, a missing file, bad CLI args. |
| 3 | Encode refused: the PCM is not pure G.711, so a lossless file cannot be made. |
Commands
info FILE [FILE ...]- Show the header, duration and bitratedecode FILE.g711.xz [OUT.wav]- Decode to a lossless stereo WAVencode FILE.wav [OUT.g711.xz]- Encode a 2-channel 16-bit 8000 Hz WAVtranscode FILE.g711.xz {u,a} OUT.g711.xz- Convert to the other law (lossy)-h, --help- Show help
Features
- Lossless round trip for mu-law and A-law recordings
- Strict encoder: refuses audio that is not pure G.711 instead of storing it with losses
- Strict reader: rejects damaged, truncated and oversized files
- Streaming decoder that never builds the whole PCM in memory
- Conversion between laws (mu-law to A-law and back)
- Optional accelerators: NumPy and a Rust extension, with a pure Python fallback
- Cross-platform (Linux, macOS, Windows)
Features Documentation - Comprehensive guide to commands, the Python API, validation rules, error messages, and examples.
File Format - Specification of the .g711.xz layout with a test vector, enough to write an independent reader or writer.
Development Tools
pip3 install -e ".[dev]"
ruff check .
ruff format --check .
mypy g711xz
# Rebuild the Rust extension in place (needs a Rust toolchain, a C compiler and an active virtualenv)
maturin develop --release
Testing
pytest --cov=g711xz --cov-report=term-missing --cov-report=xml
# CI automatically uploads coverage.xml to Codecov
# Standard library only
python3 -m unittest -v test_g711xz
License
MIT License
Metadata
Release files for g711xz 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| g711xz-0.0.2.tar.gz | 61.8 kB | With provenance | Details for g711xz-0.0.2.tar.gz |
Built distributions (wheels)
Total release size: 2.3 MB
Release files / g711xz-0.0.2.tar.gz
| Download URL | g711xz-0.0.2.tar.gz |
|---|---|
| Size | 61.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
246ae3c98f66a3523d81a3f8012b57960b7816e4623cd7591b0812057903f0b7
|
|
BLAKE2b-256 checksum How to use checksums |
a3238d5223dd572b9bd22dfb4f11b97273cfebf87b5c61e2844f5cc3ed41bf1c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.
Transparency logRelease files / g711xz-0.0.2-py3-none-any.whl
| Download URL | g711xz-0.0.2-py3-none-any.whl |
|---|---|
| Size | 12.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3994cdb52db34ddbeb6bf573624cc6367353ab9b3264cffde01f00772c00351d
|
|
BLAKE2b-256 checksum How to use checksums |
87591a91ec99f3115684ae8909ccaa8098d2f4387c37f8cd472743c0efa9f660
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.
Transparency logRelease files / g711xz-0.0.2-cp39-abi3-win_amd64.whl
| Download URL | g711xz-0.0.2-cp39-abi3-win_amd64.whl |
|---|---|
| Size | 184.9 kB |
| Tags | CPython 3.9 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
2202068d68b48d015584fb2104e079218188aa0ccc931ce490d8572ac768fbdd
|
|
BLAKE2b-256 checksum How to use checksums |
f1260d437929e5146982b31d36d89d0b7363231f141c516fe9564fac67582e47
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.
Transparency logRelease files / g711xz-0.0.2-cp39-abi3-musllinux_1_2_x86_64.whl
| Download URL | g711xz-0.0.2-cp39-abi3-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 486.8 kB |
| Tags | CPython 3.9 Linux musl 1.2+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
ed283bb52ea0e748b759d3a4098b4507a47d69d5fd46ade1acef4065590b0f40
|
|
BLAKE2b-256 checksum How to use checksums |
8502bc59680ad3dc9a6d8e04d57a59bf1c54de58f63cfcea8650a24e60379c38
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.
Transparency logRelease files / g711xz-0.0.2-cp39-abi3-musllinux_1_2_aarch64.whl
| Download URL | g711xz-0.0.2-cp39-abi3-musllinux_1_2_aarch64.whl |
|---|---|
| Size | 449.3 kB |
| Tags | CPython 3.9 Linux musl 1.2+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
a4a7eaefe3b73fbcb449ba70c0cf03a482860de477699471ce914feb7bb49ee6
|
|
BLAKE2b-256 checksum How to use checksums |
7e23cb53ca97853a4acba499fcc0a16938fa40065a584c40de0b5f972406057e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.
Transparency logRelease files / g711xz-0.0.2-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
| Download URL | g711xz-0.0.2-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
|---|---|
| Size | 274.6 kB |
| Tags | CPython 3.9 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
4c7723443a6c9858249d15732b72750b177a409540a90bfe16d0d37a761c8d39
|
|
BLAKE2b-256 checksum How to use checksums |
e997c5ccfed3914720fde773376e6d7d13a48a81bc1fa9d2e38443e505e38e13
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.
Transparency logRelease files / g711xz-0.0.2-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
| Download URL | g711xz-0.0.2-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl |
|---|---|
| Size | 270.5 kB |
| Tags | CPython 3.9 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
e149d4bddc00858532d94fd8384ec35c90c63734884b3ea4efc28fd9903eece8
|
|
BLAKE2b-256 checksum How to use checksums |
2dd158b0e7340871851e42ca25b2919a8818b43f5fbefa4840f41c4d5f13ba69
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.
Transparency logRelease files / g711xz-0.0.2-cp39-abi3-macosx_11_0_arm64.whl
| Download URL | g711xz-0.0.2-cp39-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 258.6 kB |
| Tags | CPython 3.9 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
46a8f098d99dc32cdf3efb94bf50ec7734078d7ddd6aeb640963c6ec450a34aa
|
|
BLAKE2b-256 checksum How to use checksums |
ed0af325f9b94a8cb1bc30fd7ec49b4c3ae12dda071150c646346458c79c8090
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.
Transparency logRelease files / g711xz-0.0.2-cp39-abi3-macosx_10_12_x86_64.whl
| Download URL | g711xz-0.0.2-cp39-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 267.9 kB |
| Tags | CPython 3.9 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
f8cb2290b67423c286bb1347a8a89eca82d2f7ba5c25f03c7c1ae7bd3df3cce5
|
|
BLAKE2b-256 checksum How to use checksums |
f6a3c1cdf8c5097fe2cc0dc5de5aea96d506592c69f8b963e510cbdcd3cdba81
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.
Transparency logSecurity for g711xz 0.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 9 files in this release have been uploaded with provenance metadata.
Attestation for g711xz-0.0.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.