Skip to main content

g711xz - lossless storage for G.711 call recordings

CI Coverage PyPI Downloads License Python

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 xz alone
  • ❌ Audio that is not pure G.711: refused instead of rounded
  • ❌ Metadata: the file holds the audio and nothing else

How it compares

ULAW XZ G711XZ G711XZ VOX OPUS 32 kbit/s MP3 32 kbit/s
Decodes back to the original yes yes yes speech only no no
Words matching the original transcript, % 100 100 100 99.96 94.6 95.0
Calls with a word-for-word identical transcript, % 100 100 100 99.87 71.7 71.4
Average size, kbit/s 128 23.7 20.8 18.4 20.6 32.4
5 minutes, MB 4.80 0.89 0.78 0.69 0.77 1.22
CPU usage to encode, % of Opus 0 24 13 12 100 16

ULAW is the raw 8 kHz stereo mu-law stream. XZ is xz -6 over those bytes, OPUS is opusenc --bitrate 32 --speech, MP3 is lame -b 32. The transcript rows compare a Whisper transcript of each format with the transcript of the original audio.

  • xz alone is lossless too, just bigger. It takes the bytes as they come, g711xz lays each side of the call out on its own first: xz comes out about 14% larger and takes twice the CPU.
  • G711XZ VOX is the beta VOX mode (g711xz encode in.wav --vox), off by default. Speech is kept bit for bit and long stretches of even line noise are replaced, so the file is smaller but no longer an exact copy. Any 0.0.3 reader opens it like a lossless file, and g711xz info shows the mode. See VOX Mode (Beta).
  • The recognizer is not to blame. The same audio transcribed twice agrees on 99.98% of the words and on 99.8% 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

# Beta: write a smaller VOX file, not an exact copy (writes rec.vox.g711.xz)
g711xz encode rec.wav --vox

# A VOX file is read like any other; info and the result line of decode show the mode
g711xz decode rec.vox.g711.xz

# Show help
g711xz --help

Example output of g711xz info:

rec.g711.xz:
  format    CRG7 version 1
  mode      lossless
  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"))

# Beta VOX file: off by default when writing, read like any other file
data = g711xz.encode(g711xz.read_wav("rec.wav"), vox=True)
law, frames, pcm = g711xz.decode(data)

# Need the exact recording? Check the mode
exact = g711xz.read_mode(data) != g711xz.MODE_VOX

Encoding raises g711xz.RefusedError when the PCM is not pure G.711, and reading raises g711xz.FormatError for a damaged file. A VOX file is not an error: g711xz.read_mode tells it from a lossless one.

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 bitrate
  • decode FILE.g711.xz [OUT.wav] - Decode to a lossless stereo WAV
  • encode FILE.wav [OUT.g711.xz] [--vox] - Encode a 2-channel 16-bit 8000 Hz WAV
  • transcode FILE.g711.xz {u,a} OUT.g711.xz - Convert to the other law (lossy)
  • --vox - Beta, encode only: write a VOX file. info, decode and transcode read both modes and name the mode
  • -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.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for g711xz 0.0.3
File Size Uploaded Provenance Actions
g711xz-0.0.3.tar.gz 81.0 kB With provenance Details for g711xz-0.0.3.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for g711xz 0.0.3
File Actions
g711xz-0.0.3-py3-none-any.whl Python 3 none any Details for g711xz-0.0.3-py3-none-any.whl
g711xz-0.0.3-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details for g711xz-0.0.3-cp39-abi3-win_amd64.whl
g711xz-0.0.3-cp39-abi3-musllinux_1_2_x86_64.whl CPython 3.9 abi3 Linux musl 1.2+ x86-64 Details for g711xz-0.0.3-cp39-abi3-musllinux_1_2_x86_64.whl
g711xz-0.0.3-cp39-abi3-musllinux_1_2_aarch64.whl CPython 3.9 abi3 Linux musl 1.2+ ARM64 Details for g711xz-0.0.3-cp39-abi3-musllinux_1_2_aarch64.whl
g711xz-0.0.3-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.9 abi3 Linux glibc 2.17+ x86-64 Details for g711xz-0.0.3-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
g711xz-0.0.3-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.9 abi3 Linux glibc 2.17+ ARM64 Details for g711xz-0.0.3-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
g711xz-0.0.3-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details for g711xz-0.0.3-cp39-abi3-macosx_11_0_arm64.whl
g711xz-0.0.3-cp39-abi3-macosx_10_12_x86_64.whl CPython 3.9 abi3 macOS 10.12+ x86-64 Details for g711xz-0.0.3-cp39-abi3-macosx_10_12_x86_64.whl

Total release size: 2.3 MB

Release files / g711xz-0.0.3.tar.gz

Download URL g711xz-0.0.3.tar.gz
Size 81.0 kB
Tags Source
SHA-256 checksum
How to use checksums
9242397951e054750b48807f3636d1402ef52bab5985c2af5f86e91098d163a3
BLAKE2b-256 checksum
How to use checksums
2526445da59c57db41a688fccc9c4445ce933dd062d0912e180732eb144c86ad
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 23, 2026.

Transparency log

Release files / g711xz-0.0.3-py3-none-any.whl

Download URL g711xz-0.0.3-py3-none-any.whl
Size 16.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a69011eacf39e0737931e6801ecb15a32da7ed29e9c91ad5f899bee1f0d2409a
BLAKE2b-256 checksum
How to use checksums
06ff3710779311703894a933c483e6d352e49ea34ebf3a0f2882218e69bcc919
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 23, 2026.

Transparency log

Release files / g711xz-0.0.3-cp39-abi3-win_amd64.whl

Download URL g711xz-0.0.3-cp39-abi3-win_amd64.whl
Size 189.0 kB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
65f4eafc900c4d8ae154870eeed9da86a56a106cb59d18c7a51c677554864f02
BLAKE2b-256 checksum
How to use checksums
b3d545646458ffdd746ed3152c8a5cf3f057e989fb842e8bf2a8417267b26a7d
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 23, 2026.

Transparency log

Release files / g711xz-0.0.3-cp39-abi3-musllinux_1_2_x86_64.whl

Download URL g711xz-0.0.3-cp39-abi3-musllinux_1_2_x86_64.whl
Size 490.8 kB
Tags CPython 3.9 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
cd118deab148e84973b4689339a3391147a7f9bf6d62bf8a6cf9a761df33114d
BLAKE2b-256 checksum
How to use checksums
b119cf190bb5e589b235daf8729ebad8a992744b86aecdc27122abeb0a335936
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 23, 2026.

Transparency log

Release files / g711xz-0.0.3-cp39-abi3-musllinux_1_2_aarch64.whl

Download URL g711xz-0.0.3-cp39-abi3-musllinux_1_2_aarch64.whl
Size 453.4 kB
Tags CPython 3.9 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
92e1d439bfb1bca88784c7623ea54a78c3ab8116a9d25713651c5d23327dfa88
BLAKE2b-256 checksum
How to use checksums
b703594572d25d83c8f486e58bb321534f3e14857797379bfdcaca866f344019
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 23, 2026.

Transparency log

Release files / g711xz-0.0.3-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL g711xz-0.0.3-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 278.7 kB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
fd4c88b98b5235c81e17f59c1a57a67fd77502e4aa00e8ab35f1b1081e1a97a1
BLAKE2b-256 checksum
How to use checksums
4c2af58357601aac8b59b8620e898b84b2ad8256fd93c651d992a390b00a2c70
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 23, 2026.

Transparency log

Release files / g711xz-0.0.3-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL g711xz-0.0.3-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 274.6 kB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
0735cd685ed9792c026d5631a006b3072878ced0238efc2ea050570e1258c3f3
BLAKE2b-256 checksum
How to use checksums
0d893017bfeecb487823c15d9c19fb9a7abbc4a531fb49d00f8e77524abb1f6c
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 23, 2026.

Transparency log

Release files / g711xz-0.0.3-cp39-abi3-macosx_11_0_arm64.whl

Download URL g711xz-0.0.3-cp39-abi3-macosx_11_0_arm64.whl
Size 262.6 kB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
a2ddfa2b013138bcc31e7dbf2cb950cece4852d2647a690e2144021aff21f2ff
BLAKE2b-256 checksum
How to use checksums
f2210bd1ff8b97337709b73d7252221a8ff11b8b8d0666a6092a7e45a408eadb
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 23, 2026.

Transparency log

Release files / g711xz-0.0.3-cp39-abi3-macosx_10_12_x86_64.whl

Download URL g711xz-0.0.3-cp39-abi3-macosx_10_12_x86_64.whl
Size 271.9 kB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
f4d6247eb5e56d1c56c4146defc7eb0aab049818738fdd4dfa32bef10e8aba47
BLAKE2b-256 checksum
How to use checksums
54ec71446e44de8ab91b7b74f093c9d09e95b3fa02d65ae1509b911c4a69082d
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 23, 2026.

Transparency log

Security for g711xz 0.0.3

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.

Select from 9 files

Attestation for g711xz-0.0.3.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 23, 2026.

Transparency log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page