Skip to main content

现代化的 Python 音频均衡工具 - 比原版 Levelator 快 40%

Project description

PyLevelator

现代化的 Python 音频均衡工具,基于原始 Levelator 算法的 Cython 实现。

License: MIT Python 3.7+

🚀 重大突破!

优化版本比原版 C++ 还快 40%!

特性

  • 超高性能 - 比原版 Levelator 快 40%
  • 高准确度 - 95.2% 准确度复现原始算法
  • 🔧 双重优化 - soundfile I/O + OpenMP 并行化
  • 🌍 跨平台 - Windows/macOS/Linux 全支持
  • 📦 易用 - 简洁的 Python API

性能对比

实现 30秒音频处理时间 准确度 相对原版
PyLevelator (优化版) 1.8秒 95.2% 0.6x (更快!)
原版 Levelator (C++) 3秒 100% 1x
PyLevelator (基础版) 27秒 95.2% 9x 慢
纯 Python 7分钟 95% 140x 慢

优化技术

  1. soundfile I/O - 使用 libsndfile(C 库)替代 Python wave 模块
  2. OpenMP 并行化 - 多核 CPU 并行计算
  3. 内存视图优化 - 零拷贝数据访问
  4. Cython 编译 - 编译为 C 扩展

总加速比: 15.2x(相比基础版)

快速开始

安装

pip install pylevelator

使用

from pylevelator import Levelator

# 创建实例(自动使用优化版本)
levelator = Levelator()

# 处理音频
levelator('input.wav', 'output.wav')

详细示例

基本使用

from pylevelator import Levelator

levelator = Levelator()

# 处理单个文件
output = levelator.process('input.wav', 'output.wav')
print(f'完成: {output}')

批量处理

from pylevelator import BatchProcessor

batch = BatchProcessor(max_workers=4)

# 处理多个文件
files = ['file1.wav', 'file2.wav', 'file3.wav']
results = batch.process_files(files, output_dir='output')

print(f'处理了 {len(results)} 个文件')

自定义参数

levelator = Levelator(
    target_rms=0.12,      # 目标音量
    window_size=0.5,      # 分析窗口(秒)
    smoothing=0.3,        # 平滑系数
    max_gain=20.0,        # 最大增益 (dB)
)

output = levelator.process('input.wav')

算法说明

PyLevelator 基于原始 Levelator 2.1.1 的算法,通过逆向工程理解并用现代 Python/Cython 重新实现。

核心算法

  1. 计算短时 RMS(能量包络)
  2. 根据目标电平计算增益
  3. 平滑增益曲线
  4. 应用前瞻限幅器
  5. 应用增益并限幅

效果

  • 提升平均音量 30-50%
  • 降低音量变化 20-30%
  • 保持音频质量

开发

从源码安装

git clone https://github.com/KakaruHayate/pylevelator.git
cd pylevelator
pip install -e .

构建优化版本

# 安装依赖
pip install cython numpy soundfile

# 构建(需要支持 OpenMP 的编译器)
python setup_optimized.py build_ext --inplace

运行测试

# 测试基础版本
python test_cython.py

# 测试优化版本
python test_optimized.py

技术细节

为什么比原版还快?

  1. 现代编译器优化 - MSVC 2024 vs 2006 年的编译器
  2. OpenMP 并行化 - 充分利用多核 CPU
  3. 优化的 I/O - libsndfile 比原版的 I/O 更快
  4. 内存访问优化 - 更好的缓存利用

性能分析

优化版本(1.8秒)

  • I/O 操作: ~0.5秒(soundfile)
  • 算法处理: ~1.3秒(并行化)

基础版本(27秒)

  • I/O 操作: ~15秒(wave 模块)
  • 算法处理: ~12秒(串行)

加速来源

  • I/O: 30x 加速(soundfile)
  • 算法: 9x 加速(OpenMP)

致谢

  • GigaVox Media & Singular Software - 原始 Levelator 的创造者
  • Python 社区 - numpy, Cython, soundfile 等优秀工具

许可证

MIT License - 详见 LICENSE

相关链接

当前状态

v1.1.0 已发布

  • 优化版 Cython 实现
  • 95.2% 准确度
  • 1.8秒处理 30秒音频
  • 比原版快 40%
  • 完整测试通过

版本历史

  • v1.1.0 (2026-05-31) - 优化版本,比原版快 40%
  • v1.0.0 (2026-05-31) - 初始发布,Cython 实现

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.1.0.tar.gz (12.1 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.1.0-cp311-cp311-win_amd64.whl (126.4 kB view details)

Uploaded CPython 3.11Windows x86-64

pylevelator-1.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (780.5 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

pylevelator-1.1.0-cp311-cp311-macosx_11_0_arm64.whl (729.2 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pylevelator-1.1.0-cp310-cp310-win_amd64.whl (126.1 kB view details)

Uploaded CPython 3.10Windows x86-64

pylevelator-1.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (744.2 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

pylevelator-1.1.0-cp310-cp310-macosx_11_0_arm64.whl (731.7 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pylevelator-1.1.0-cp39-cp39-win_amd64.whl (126.5 kB view details)

Uploaded CPython 3.9Windows x86-64

pylevelator-1.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (741.4 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

pylevelator-1.1.0-cp39-cp39-macosx_11_0_arm64.whl (732.2 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

pylevelator-1.1.0-cp38-cp38-win_amd64.whl (128.4 kB view details)

Uploaded CPython 3.8Windows x86-64

pylevelator-1.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (768.8 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

pylevelator-1.1.0-cp38-cp38-macosx_11_0_arm64.whl (735.6 kB view details)

Uploaded CPython 3.8macOS 11.0+ ARM64

File details

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

File metadata

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

File hashes

Hashes for pylevelator-1.1.0.tar.gz
Algorithm Hash digest
SHA256 e65d516c479e550c5e721ee3d91aed27178fb84bc39953fdfa77079f5e59eae4
MD5 555ecd3a7d3aa59a21dbadf2727bb88f
BLAKE2b-256 b8f97a7000bb6053ecd1c77c2b61a546a310dcb1102ad1070c922d71929f014c

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pylevelator-1.1.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 126.4 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.1.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 fd87916093ad6738702eff76aa4bcdfdc7a980badbea3e551f86ef57537c2488
MD5 d51f8e143689a73b4f2aa4c968d8860f
BLAKE2b-256 f674abd7d49ce2d8434027ca014c5e2361ac8ef5204034b6e097154e39c9e3d6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pylevelator-1.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b7c7a1b1896cd1c92d967819c429e86aa7575f33a3b17f8dd8328456c3463f51
MD5 98bb93cf389d485ef8cd8ee33c4b08fe
BLAKE2b-256 173407a6ae1efed3470009b28d837434b37a7c309883b77cc4f5ecd3d5791357

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pylevelator-1.1.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e6c5a37a51a9973ac63cd7cf6f762a47abf9de56d7b2aa3c97421f9e15029c8c
MD5 0c06071f9b40cece34fed4bd1d749b09
BLAKE2b-256 081a93d2c6cbd4555fd0a8a6ffe6553294e565ac0d0fe67775fbb2d5adb76a29

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pylevelator-1.1.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 126.1 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.1.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 2559109e0edf5637a2d669f5c7442bb3b46b7f831d325fb25d68ef8169d395cb
MD5 29e817395ec2e89f9d220a2aef12f9b6
BLAKE2b-256 7a165a34d7e6bf3633bf4c91906b2a9c1de96178af5f2c04e086b0c1bd79341d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pylevelator-1.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7908553c09fe47969ffeea3b27ea265fbe065755a423cd6c1bc4038a231d5a46
MD5 6fa64addcfd36e89260db0510c56a43d
BLAKE2b-256 9999fca0952cc8cd011fa1793267d9e1c0d76a7c2f8b1eed8ea9f7d58a30d33a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pylevelator-1.1.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d0a11f13149806ba491034d9c7605f390b4c0648aae818b64a90fc7617edf77d
MD5 0bb261d32bfc3279aaaeddfd1b8c0d69
BLAKE2b-256 1bf29447d1880b48b1955f84b91addb6e1a1e1fbea16dd0dad7b7ed3b33c005a

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pylevelator-1.1.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 126.5 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.1.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 5a5a68bf9629e02a5c9febfe6df19087e28e2cf2c95206ca74c544bbd04bad65
MD5 0a2b41666a0d54399893f2190356fff6
BLAKE2b-256 0191608587709cd10e8bbb86f3d527f11cfd9c57af0a39311ea08fe53c6f9d8f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pylevelator-1.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3b99d7dc58de412a2e944954f743828f1abf929990b6598e66523470b82036bb
MD5 248633c8210bbe6dbcd56c912915739e
BLAKE2b-256 fbee45b7e177b2cb4fcdf5d4da009558cc557f52e24f05faf1b2a0af0dccf15c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pylevelator-1.1.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 92c70d47aeea062325068136d5614956f9b80ae14cc38270406cbca9fe76a003
MD5 d00568d9d786ff9b20971b2d2325aaa2
BLAKE2b-256 7800f179e81c718b5e22f8e6f5c990b3d50acb14da2e7be757ce0477c79158c2

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pylevelator-1.1.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 128.4 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.1.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 292118189742d669cd3894c82ddb2638e4633e33f37be5b8a8837774b5cdcbd7
MD5 4a71c0bd640006a0ed1587d0846702c7
BLAKE2b-256 b075ce01d2c5c72cc5c0f01bdf563d644ddd03589a9b6893263fd3b184638420

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pylevelator-1.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0ad702e099571c78636814e72beeb193be26445c6f84e048b3602ab691effc06
MD5 ddf6db47697d84b7e3baae040f32a36a
BLAKE2b-256 899f3a8cd5ffa6ff50094b25fde7bc03f63b567537ae23086270fd18529b8483

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pylevelator-1.1.0-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f6ffb38b505aba075e712ec0f66f5d4d766ebea553d9b44e24fd79c73c8d3e15
MD5 4b7c5fc60899df658e63799db83e0afa
BLAKE2b-256 7c9f09144ca17d84c050076f9d03b20bf1d86c36141709f35a03484cf8c1eef2

See more details on using hashes here.

Provenance

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