Skip to main content

Modern Python audio leveling tool — 40% faster than the original Levelator

Project description

PyLevelator

中文文档

A modern Python implementation of the Levelator audio leveling tool, with a command-line interface and Python API.

Features

  • Fast — ~40% faster than the original C++ Levelator (1.8s vs 3.0s for 30s audio)
  • Cross-platform — Windows, macOS, Linux; Python 3.8+
  • Easy to installpip install pylevelator
  • Configurable — tune RMS target, gain limits, smoothing, lookahead
  • CLI + API — use from the command line or integrate as a library

Performance

Benchmarked on 30s audio (44.1 kHz, mono, Intel i7, 8 threads):

Implementation Time Relative
Original Levelator (C++, 2010) 3.0s 1.0×
PyLevelator 1.8s 1.7× faster

How It Works

PyLevelator processes audio through five stages to balance loudness:

  1. RMS Envelope Calculation — slides a window (default: 0.5s) over the audio and computes the root-mean-square energy at each position. This gives a smoothed representation of how loud the audio is at every moment.

  2. Gain Curve Calculation — at each sample, computes how much gain (in dB) is needed to bring the local RMS up to the target level. Gain is clamped to the [min_gain, max_gain] range (default: [-10 dB, +20 dB]).

  3. Gain Smoothing — applies a moving-average filter (default: 0.3s) to the gain curve so that adjacent samples don't jump abruptly. Without this, the output would sound "choppy" or "pumping".

  4. Lookahead Limiting — scans forward in time and pre-emptively reduces gain before any peak that would exceed the clipping threshold. The reduction is spread over the preceding lookahead window (default: 0.1s). This is the key step that makes Levelator sound natural — it reacts to peaks before they happen rather than after.

  5. Gain Application — multiplies each audio sample by its corresponding gain value and hard-limits the output to ±0.99 to prevent digital clipping.

The result: quiet passages are boosted, loud passages are gently tamed, and the overall recording feels consistently loud without the "pumping" artifacts of simple compressors.

Installation

From PyPI (recommended)

pip install pylevelator

Pre-built wheels for Python 3.8–3.11 on Windows, macOS (arm64 + x86_64), and Linux.

From source

Requires a C compiler with OpenMP support:

  • Windows — MSVC (Visual Studio 2019+)
  • macOS — libomp (brew install libomp)
  • Linux — GCC with libgomp
git clone https://github.com/KakaruHayate/pylevelator.git
cd pylevelator
pip install .

Quick Start

Command line

pylvl -i input.wav -o output.wav
pylvl -i input.wav -o output.wav --target-rms 0.15
pylvl -i input_dir/ -o output_dir/
pylvl --help

Python API

from pylevelator import Levelator, process

# Basic usage
lv = Levelator()
lv.process("input.wav", "output.wav")

# Custom parameters
lv = Levelator(target_rms=0.15, max_gain=18.0, smoothing=0.4)
lv.process("input.wav", "output.wav")

# One-liner
process("input.wav", "output.wav", target_rms=0.15)

CLI Options

Flag Default Description
-i, --input required Input audio file or directory
-o, --output required Output audio file or directory
--target-rms 0.12 Target RMS level (0.0–1.0)
--window-size 0.5 Analysis window in seconds
--smoothing 0.3 Gain smoothing window in seconds
--max-gain 20.0 Maximum gain in dB
--min-gain −10.0 Minimum gain in dB
--lookahead 0.1 Lookahead time in seconds
--pattern *.wav File pattern for batch mode
-v, --verbose off Verbose output

Parameter Guide

  • target-rms — target loudness level. Higher = louder output.

    • Podcasts / voice: 0.15–0.20 (louder)
    • Music / dynamic content: 0.08–0.12 (preserve dynamics)
    • Default (0.12) is roughly −18 dBFS.
  • window-size — how quickly the algorithm reacts to volume changes.

    • Smaller (0.2–0.3s): faster, more aggressive
    • Larger (0.5–1.0s): slower, smoother, preserves dynamics
  • smoothing — how smooth the gain transitions are.

    • Larger (0.4–0.6s): fewer abrupt changes, may feel sluggish
    • Smaller (0.1–0.2s): quicker response, may sound less natural
  • max-gain / min-gain — safety rails.

    • Lower max-gain if you hear noise in boosted quiet sections.
    • Raise min-gain if you want to preserve the original dynamics more.
  • lookahead — time window for the peak limiter.

    • Larger (0.15–0.2s): more clipping protection, slightly slower response
    • Smaller (0.05–0.1s): snappier, less headroom

Supported Formats

PyLevelator uses soundfile for I/O, supporting: WAV, FLAC, OGG, AIFF, CAF, and more. The output format matches the input format automatically.

License

MIT — 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

pylevelator-1.2.0.tar.gz (178.3 kB view details)

Uploaded Source

Built Distributions

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

pylevelator-1.2.0-cp311-cp311-win_amd64.whl (256.9 kB view details)

Uploaded CPython 3.11Windows x86-64

pylevelator-1.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (756.9 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

pylevelator-1.2.0-cp311-cp311-macosx_11_0_arm64.whl (860.1 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pylevelator-1.2.0-cp310-cp310-win_amd64.whl (256.7 kB view details)

Uploaded CPython 3.10Windows x86-64

pylevelator-1.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (727.8 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

pylevelator-1.2.0-cp310-cp310-macosx_11_0_arm64.whl (861.9 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pylevelator-1.2.0-cp39-cp39-win_amd64.whl (257.1 kB view details)

Uploaded CPython 3.9Windows x86-64

pylevelator-1.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (726.1 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

pylevelator-1.2.0-cp39-cp39-macosx_11_0_arm64.whl (862.3 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

pylevelator-1.2.0-cp38-cp38-win_amd64.whl (256.2 kB view details)

Uploaded CPython 3.8Windows x86-64

pylevelator-1.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (745.6 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

pylevelator-1.2.0-cp38-cp38-macosx_11_0_arm64.whl (863.1 kB view details)

Uploaded CPython 3.8macOS 11.0+ ARM64

File details

Details for the file pylevelator-1.2.0.tar.gz.

File metadata

  • Download URL: pylevelator-1.2.0.tar.gz
  • Upload date:
  • Size: 178.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pylevelator-1.2.0.tar.gz
Algorithm Hash digest
SHA256 bbd82d1edbce1e745332642d7d89e35f60f11fe9df79c1d6c7067958e87f031a
MD5 18db65782fcdbe4d54a8f99ca3ff55b9
BLAKE2b-256 5f4ae62e1a1da1c10842281ffe6485d2ba528b1b6edf21557a5ef207843b8b15

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylevelator-1.2.0.tar.gz:

Publisher: python-publish.yml on KakaruHayate/pylevelator

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

File details

Details for the file pylevelator-1.2.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: pylevelator-1.2.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 256.9 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pylevelator-1.2.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 529e694651156fa0abc14b793c4d15a3bb05d698a41e6f01102547a0d9e2479d
MD5 5d8b9535d535b8ec1239f4195f7530e3
BLAKE2b-256 9122c8783240d478dbf521ad60390b28913a8b2e49253bf084c8e3e34dc3af4f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylevelator-1.2.0-cp311-cp311-win_amd64.whl:

Publisher: python-publish.yml on KakaruHayate/pylevelator

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

File details

Details for the file pylevelator-1.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pylevelator-1.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0d32ab3d58f0ae80d3a369aae10c33e8af41201e8bbb79f3c2dad48c050bd974
MD5 ea7de56e6da6a4c4f1ac8ef0e8d23eff
BLAKE2b-256 4e3f74c9f5d8cae110d35309ede02e8e5f2131fb7f9c3db495f3a645b75176cb

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylevelator-1.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: python-publish.yml on KakaruHayate/pylevelator

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

File details

Details for the file pylevelator-1.2.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pylevelator-1.2.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6cbcba19c04ac93b1acacbd3f2ecd4523da5225a6676eec7bce54d24f7c953ab
MD5 46d5ff33ccac37ad8c093d76e3d4f20f
BLAKE2b-256 50254fee1287959b347c22d44bcd08180c0f27d4cb2e344e4c363f97580c2595

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylevelator-1.2.0-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: python-publish.yml on KakaruHayate/pylevelator

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

File details

Details for the file pylevelator-1.2.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: pylevelator-1.2.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 256.7 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pylevelator-1.2.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 5664c663ce8df8377b91de3f30c02b829049d2048d5bec7b2d46bfb3a2b43d9d
MD5 049930b014e80752569487bc2eedff76
BLAKE2b-256 fb06af8c6f3a95dfefaecba87abd79fbef4a8f1fdb7bbbfafb470e46e61cb44e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylevelator-1.2.0-cp310-cp310-win_amd64.whl:

Publisher: python-publish.yml on KakaruHayate/pylevelator

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

File details

Details for the file pylevelator-1.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pylevelator-1.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c12c1bad53d2d498ca0505d780dc84436c99f9236a7da457d3f83c72754d7594
MD5 fd45b264e4020f8587a82c0dc828443f
BLAKE2b-256 8f91154808ae66053255e184a43d680a14e93ca69e93a8a97bf41266319ffd67

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylevelator-1.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: python-publish.yml on KakaruHayate/pylevelator

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

File details

Details for the file pylevelator-1.2.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pylevelator-1.2.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 acc11ecfaee71bcb997675be327eadc12cc3bd49b83936b840e35f988e47eb53
MD5 18abe815f41e8e282dc0999fdeb6d05d
BLAKE2b-256 3fe5979841a62f32962c770c1716831c42633fd041ae92dddb8f62f7f758be5f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylevelator-1.2.0-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: python-publish.yml on KakaruHayate/pylevelator

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

File details

Details for the file pylevelator-1.2.0-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: pylevelator-1.2.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 257.1 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pylevelator-1.2.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 f945db8c1f7f2bc87dadb22a199c03801fd0669fb110a48570389f460b3fa6e0
MD5 3b94902637c6aaf9f042f9a67e62effc
BLAKE2b-256 bdf3a04ac1d2de8bea47e2e720cfe1bce801f8dd02f049a628c4ee353886a2f7

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylevelator-1.2.0-cp39-cp39-win_amd64.whl:

Publisher: python-publish.yml on KakaruHayate/pylevelator

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

File details

Details for the file pylevelator-1.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pylevelator-1.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 60aaccc335ddefa0a67d8fd47350d9680f23a6a73dbbbf5ed20526cb70c8dd87
MD5 0a8937261d74a529385801a73a22cce6
BLAKE2b-256 5d64fbcddbf871f8dcb58719b2f07229a72eadd20f5e7589c5ac89fef04dcafd

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylevelator-1.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: python-publish.yml on KakaruHayate/pylevelator

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

File details

Details for the file pylevelator-1.2.0-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pylevelator-1.2.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 43bddfb69560c39e0c2492e5ad6d88155aef34a359fb7c10a87d247f7b06673e
MD5 b14e989f6b3c510d7d56cb095c5439bc
BLAKE2b-256 de01106c4a984a8020bb5875bb5e5c8f08680c82853469a57d6433ccf633a03d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylevelator-1.2.0-cp39-cp39-macosx_11_0_arm64.whl:

Publisher: python-publish.yml on KakaruHayate/pylevelator

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

File details

Details for the file pylevelator-1.2.0-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: pylevelator-1.2.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 256.2 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pylevelator-1.2.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 6bd83b1cd7bbb740288616cba4b619e39d2029826dd33762decfb1ce49dd1dfc
MD5 1d05b8542470d043d3a0b5da62294a26
BLAKE2b-256 273caf35c8b40916750c2ce9c155269e68e340cfcae04cbbe0c06868c2ed9dbb

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylevelator-1.2.0-cp38-cp38-win_amd64.whl:

Publisher: python-publish.yml on KakaruHayate/pylevelator

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

File details

Details for the file pylevelator-1.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pylevelator-1.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a85601c480068bbbc0ad9a42952a9c2d7194b63e342725b057f670efe52f043e
MD5 d65d41f4830db4e8a99138928575b83a
BLAKE2b-256 b82d92f927cb3feefb385d0080c3da89b078667a2aa93c0ade3196ed423c9e1f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylevelator-1.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: python-publish.yml on KakaruHayate/pylevelator

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

File details

Details for the file pylevelator-1.2.0-cp38-cp38-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pylevelator-1.2.0-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cbd5904d27c64d4b508a46baee048a4259bb1b1407fe7b0313bbea2f66af94aa
MD5 92b621c044bd00552c6fc6c507f28f50
BLAKE2b-256 c042fba3232099504128d050645528fc206123d8890db26f7c8ff3986faaf58c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylevelator-1.2.0-cp38-cp38-macosx_11_0_arm64.whl:

Publisher: python-publish.yml on KakaruHayate/pylevelator

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