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.1.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.1-cp311-cp311-win_amd64.whl (256.9 kB view details)

Uploaded CPython 3.11Windows x86-64

pylevelator-1.2.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (757.0 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

pylevelator-1.2.1-cp311-cp311-macosx_11_0_arm64.whl (860.2 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pylevelator-1.2.1-cp310-cp310-win_amd64.whl (256.8 kB view details)

Uploaded CPython 3.10Windows x86-64

pylevelator-1.2.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (727.9 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

pylevelator-1.2.1-cp310-cp310-macosx_11_0_arm64.whl (862.0 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pylevelator-1.2.1-cp39-cp39-win_amd64.whl (257.2 kB view details)

Uploaded CPython 3.9Windows x86-64

pylevelator-1.2.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (726.2 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

pylevelator-1.2.1-cp39-cp39-macosx_11_0_arm64.whl (862.4 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

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

Uploaded CPython 3.8Windows x86-64

pylevelator-1.2.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (745.7 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

pylevelator-1.2.1-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.1.tar.gz.

File metadata

  • Download URL: pylevelator-1.2.1.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.1.tar.gz
Algorithm Hash digest
SHA256 518ed780f54f74d306b3440e3e23f47c2f75647f7c8258278743059626a76f36
MD5 7a4360b19e52eec96f2a2f23cdeb34ad
BLAKE2b-256 1aa32fb1f42cfc5cf4a553d39017c1ee40fd78145e0cbb37470d409e46dfba75

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylevelator-1.2.1.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.1-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: pylevelator-1.2.1-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.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 7f7a4556e8c20a0aa2ac76f75db3beb76908c1707b147ec4ceb932caa56fcdbc
MD5 9c0e08ec15e8bb3babc47242a689f4cb
BLAKE2b-256 4bccaf23a093a829bd987b54712878c28129b0c34adc7220d63a2c7e8bce4e25

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylevelator-1.2.1-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.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pylevelator-1.2.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ff7c83c1b8a98adba16cfa66855acfacdceb3d612dac8ed0f73523edbb61a414
MD5 80c47eae8cfc37e9968aff92c9382368
BLAKE2b-256 fffa67ef5fa115b5238de99cfef4894bdef1db8d3e5e67f96beb54077d588073

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylevelator-1.2.1-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.1-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pylevelator-1.2.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 77781acc1fd4107b57dabbb7b8aeb361bbbe6c5f2ad2cd7d4beeb6d52a1618ec
MD5 374d9b5c934b3efa037871630e8a5722
BLAKE2b-256 6fc7267af17a20d4c88ecf4f3f467f07b7bc12abdc55c3e72b1d8bc04fb5fe1e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylevelator-1.2.1-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.1-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: pylevelator-1.2.1-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 256.8 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.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 67159739f708f31d1b064df9355780be4dfc51f9cf13bf8a665973c715e5be53
MD5 3825283ac650b0df6151b9f2c2e067ac
BLAKE2b-256 ce4b3834acd3a42dc288ee07c97ff94a46a640a72c5785c737c9191242e4950c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylevelator-1.2.1-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.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pylevelator-1.2.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 989b3495ad7a1c2aaa2f2a5eeb304e9799596aee3707953d63d5a4ab9ffdd133
MD5 91988b3fd4bd45fedf9e2e467824ba28
BLAKE2b-256 a780c756e9db8ad0af1f81c7965e5c2aee803196df5b7a933792bd2b2b41ad1b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylevelator-1.2.1-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.1-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pylevelator-1.2.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5daec1485c097a22e62dd88721681588a6df679e07909802fa251bfbc62ea9a1
MD5 a2fcfd344c344cda7e05843658fbdbaf
BLAKE2b-256 d0ab1e1d6b7b00bca052edae8eb9dcdb089ee01c2b2874856bfd1d2beccb31ef

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylevelator-1.2.1-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.1-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: pylevelator-1.2.1-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 257.2 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.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 fc6acf1f6fae1e50f9dff270c3514f758d65486f6a105825aa28ec5be4eb2302
MD5 03251c1523e4a9e509e0f4b236059122
BLAKE2b-256 5017a2662e7e192e40f96761b2d807cc4a7146c46d34bd31cf4902d5c00fd3ab

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylevelator-1.2.1-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.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pylevelator-1.2.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bc084857597943ec5dca9cc4dc6c2292f31d46cc9380329f0a96e22051760e6c
MD5 c08413f37ac110ab259f9762961d22f2
BLAKE2b-256 f84e1b6fad6e70b852ac8119350b20d02ee51c2785aac70fe87c02cdc104b75e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylevelator-1.2.1-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.1-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pylevelator-1.2.1-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fff38d9c3abbab0698e90035749b842cb0e730bef71991b9b36d30b03961fc92
MD5 51d5c78298bc3ad6a2455f639e38d01d
BLAKE2b-256 d48e06e275fbf28bd48c7a78c4e69d73f102e5b752a11eba76195c218d8e5e9e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylevelator-1.2.1-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.1-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: pylevelator-1.2.1-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.1-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 a4cebaa9923dcfbc92fd711c88053e2c60da54dced36118e86f434905d535566
MD5 dd878ca74c32f93668a195861f33db9d
BLAKE2b-256 39e3b6d801578295a1cef36fc73c6d4de0c2f48fa6727125f4128e2d64702b63

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylevelator-1.2.1-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.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pylevelator-1.2.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 46cbef5809f20b59cf00f63d3ad3a3f7aa8957cd313c8684ba8b8d2011e5aab0
MD5 c43c5bb4ff99d68a296ef845b6b037fe
BLAKE2b-256 66dd872510aac80d8481e82be8b07135f932d81aaafcd42f8871096bb1d2ab92

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylevelator-1.2.1-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.1-cp38-cp38-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pylevelator-1.2.1-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 483a4020133a8c18efdc3872ee22cb279b5146b2be85caa072673b7426582847
MD5 ac8d4f695b34e01f09a8532f81823735
BLAKE2b-256 4822027321e9dd2f4c757c1d861d1514bc06eca05623a3328e76b1e3f3a985ab

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylevelator-1.2.1-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