specux
Differentiable audio DSP for Python: fast, fused kernels on GPU and CPU.
Spectral transforms, an FFT family, and audio I/O, on numpy, torch, and cupy arrays alike.
Documentation: https://specux.com
import specux
y, sr = specux.audio.load("song.flac", sr=16000, mono=True)
M = specux.melspectrogram(y, sr=sr, n_fft=1024, n_mels=80)
import torch
x = torch.randn(8, 32768, device="cuda", requires_grad=True)
S = specux.stft(x, n_fft=1024, output="power") # stays on the GPU
S.sum().backward() # native adjoint kernels
Arrays go in and come out in their own library: numpy in, numpy out; torch in, torch out (resident on its device, differentiable); cupy in, cupy out. The GPU kernels are generated in C++ and compiled at runtime (NVRTC for CUDA, MSL for Metal), so one build covers every size, precision, and output mode; the CPU backend carries the same transforms and adjoints, so training works without a GPU.
What's in the box
- Spectral transforms:
stft/istft,melspectrogram,mfcc,lfcc,cqt/vqt/chroma, with output modescomplex/magnitude/power/dband configured class twins (specux.STFT,specux.MFCC, ...).specux.transformsadds torchnn.Modulewrappers with torchaudio-shaped defaults. - FFT family:
fft/ifft/rfft/irfftat any length (powers of two, smooth sizes, primes) and precision (float32, float64, and float16 storage with float32 compute), plus reusable plans (fft_plan,stft_planwith optional autotuning). - Audio I/O (
specux.audio): decode and encode WAV/FLAC/MP3/OGG/MP4, frame-accurateoffset/duration, batchload_many/save_many, streaming readers and writers for multi-hour files, resampling, loudness / true-peak / loudness-range metering, and tags/cover metadata. - torch integration: every entry point is a
torch.librarycustom op, sotorch.compile(fullgraph=True)traces without graph breaks andtorch.autocastcomputes in float32. torch stays optional: without it, numpy arrays run on the CPU engine or the torch-free CUDA runtime. - Runtime options:
specux.deterministic(True)switches overlap-adds to bitwise-reproducible kernels (and followstorch.use_deterministic_algorithms);specux.benchmark(True)autotunes new configurations once and caches the result on disk.
Install
pip install specux # CPU everywhere; CUDA/Metal where the wheel includes them
pip install specux[cuda12] # + NVRTC and CUDA headers from NVIDIA's pip wheels
pip install specux[cuda13] # the same for CUDA 13
pip install specux[torch] # torch bundles its own CUDA, nothing extra needed
Or from source, in the environment you plan to use it in:
pip install -e .
The build is torch-free (no libtorch anywhere), so one build serves numpy,
cupy, and whichever torch is installed at runtime. Python >= 3.10,
numpy >= 1.22; torch optional (>= 2.4 for autograd and torch.compile,
= 2.7 for resident Metal).
- CUDA: builds when a toolkit is found (
SPECUX_CUDA_HOMEoverrides); running needs an NVIDIA driver plus NVRTC from a toolkit, torch, or thenvidia-*pip wheels. Skipped with a notice otherwise. - CPU: always builds.
SPECUX_CPU_ONLY=1forces a CPU-only build. - macOS: builds the CPU and Metal extensions out of the box (metal-cpp is vendored).
- Audio I/O: needs FFmpeg dev libraries; on Windows,
scripts/get_ffmpeg.ps1fetches a self-contained LGPL build andscripts/get_taglib.ps1adds tag/cover support. Without FFmpeg the audio module is skipped and everything else works. - Windows:
./scripts/build.ps1imports the MSVC environment and builds in place.
Usage
import numpy as np
import specux
x = np.random.randn(8, 32768).astype(np.float32)
# functional, any array library
S = specux.stft(x, n_fft=1024, hop_length=256, output="power")
y = specux.istft(specux.stft(x, 1024), 1024, length=x.shape[-1])
C = specux.mfcc(x, sr=16000, n_mfcc=20)
# configured twins: construct once, call with (..., time)
t = specux.MelSpectrogram(sr=44100, n_fft=1024, n_mels=80)
M = t(x)
# pick a backend explicitly (default follows the input)
S = specux.stft(x, n_fft=1024, backend="cpu")
import torch
xt = torch.randn(8, 32768, device="cuda")
# torch.compile and autocast
f = torch.compile(lambda v: specux.stft(v, 1024, output="power"), fullgraph=True)
with torch.autocast("cuda", torch.float16):
S = specux.stft(xt, 1024) # computes in float32
# reusable plan; tuning knobs live only here
plan = specux.stft_plan(n_fft=1024, hop_length=256, output="power", device="cuda")
plan = specux.autotune(xt, plan) # optional, cached on disk
S = plan(xt)
# audio: read, meter, transform, write
y, sr = specux.audio.load("take.wav", sr=16000, mono=True)
lufs = specux.audio.loudness(y, sr)
y = specux.audio.normalize(y, mode="lufs", target_db=-14.0, sr=sr)
specux.audio.save("out.flac", y, sr)
for block in specux.audio.blocks("4hours.flac", 30 * sr, sr=sr, mono=True):
M = specux.melspectrogram(block, sr=sr) # constant memory
Design
A transform is one fused kernel. The C++ codegen (src/codegen/) assembles
each kernel from three parts:
- a prologue that frames, reflect-pads, and windows the signal,
- an FFT core picked by size and precision,
- an epilogue that finishes the op in the same pass: the Hermitian
recombine, then the output mode (
complex/magnitude/power/db), a filterbank reduce for mel, a wavelet-basis reduce for the CQT family, or the spectrum product for convolution.
The spectrum never round-trips through memory between those stages: a dB mel spectrogram is one kernel, and features like MFCC or chroma are short chains of them. Every backward pass is the analytic adjoint of the same chain, generated the same way. Op, direction, and mode select the prologue and epilogue, precision is a type parameter, and size is a plan, so adding a size or mode never adds a hand-written kernel. Lengths past a GPU block's shared memory decompose into a two-kernel four-step pipeline, and large prime factors take a chirp-z (Bluestein) route through the same machinery.
The same sources emit the CUDA and Metal dialects, and the CPU engine
(src/cpu/) implements the same transforms and adjoints. src/README.md
describes the native layout and layering rules.
Tests cover correctness, autograd, torch.compile, autocast, and audio;
every numerical tolerance lives in tests/_tol.py with its derivation.
python -m pytest tests # correctness, autograd, compile, autocast, audio
python bench/bench_matrix.py # timing matrix on your own hardware
License
MIT. Vendored third-party components and their licenses are listed in NOTICE.
Metadata
Release files for specux 0.1.0
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 |
|---|---|---|---|---|
| specux-0.1.0.tar.gz | 867.6 kB | Without provenance | Details for specux-0.1.0.tar.gz |
Built distributions (wheels)
Total release size: 386.5 MB
Release files / specux-0.1.0.tar.gz
| Download URL | specux-0.1.0.tar.gz |
|---|---|
| Size | 867.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f65e4324a742ebf469e1654770ce0282a4fbb512082ed93cfac2df5cf30e3d26
|
|
BLAKE2b-256 checksum How to use checksums |
bffaff776627fe57148ad90d8cdd0e2ca4a97f3a1a288c093e551a058d7b67e6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.12
|
Release files / specux-0.1.0-cp313-cp313-win_amd64.whl
| Download URL | specux-0.1.0-cp313-cp313-win_amd64.whl |
|---|---|
| Size | 42.8 MB |
| Tags | CPython 3.13 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
7b826a6acf923ad0fd2c0ccd179e8ef3af3a1299cb14e45d35d9beb9cc404acb
|
|
BLAKE2b-256 checksum How to use checksums |
5095542187562c9f85cbe45985f251860b5a9337ec61fdb119bc3bff0e0c6d68
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.12
|
Release files / specux-0.1.0-cp313-cp313-manylinux_2_28_x86_64.whl
| Download URL | specux-0.1.0-cp313-cp313-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 43.5 MB |
| Tags | CPython 3.13 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
c187569090c592cce7c4792f4d2fb200af78e87f9c41c1c97ae5be6f2b3f3f62
|
|
BLAKE2b-256 checksum How to use checksums |
608a70ac392ff5983373a4828a1244ab4be5654b703cd91767ba74814ac0b4a2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.12
|
Release files / specux-0.1.0-cp313-cp313-macosx_11_0_arm64.whl
| Download URL | specux-0.1.0-cp313-cp313-macosx_11_0_arm64.whl |
|---|---|
| Size | 10.2 MB |
| Tags | CPython 3.13 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
6b149da11236ae5b8b5a7b5a9e6e773e63781919a1f8169ff69f600ca9378e66
|
|
BLAKE2b-256 checksum How to use checksums |
c22870778cf3da439bb03e72ae211e54227b211f0de56ac7f0f040394ccf9f48
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.12
|
Release files / specux-0.1.0-cp312-cp312-win_amd64.whl
| Download URL | specux-0.1.0-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 42.8 MB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
3ae615822ec95f6c85458031d3378a34f73dd0fda7db5dbdd62a6ec5e96eaf39
|
|
BLAKE2b-256 checksum How to use checksums |
e5650337663d95bea08776e6e33a6247f817d04c2967229db52fb03baae0ed87
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.12
|
Release files / specux-0.1.0-cp312-cp312-manylinux_2_28_x86_64.whl
| Download URL | specux-0.1.0-cp312-cp312-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 43.5 MB |
| Tags | CPython 3.12 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
e47fb4f125aa9bafb9c38e2cb160ec2b2b820f724f735fce87384c7f2d21af96
|
|
BLAKE2b-256 checksum How to use checksums |
c48ab1684a9a89a39db8a4a8779c0ea21c5d39acd9753d56806c3c43567a512f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.12
|
Release files / specux-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
| Download URL | specux-0.1.0-cp312-cp312-macosx_11_0_arm64.whl |
|---|---|
| Size | 10.2 MB |
| Tags | CPython 3.12 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
8f5b3477f342ad29731b9badad3acd36b0e51c999a3df6a117afaf2c32df56b9
|
|
BLAKE2b-256 checksum How to use checksums |
24f1c4a76cd17c33f69a4556f79f99c6cfdc152392b098ddd4d683116e7bdd9f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.12
|
Release files / specux-0.1.0-cp311-cp311-win_amd64.whl
| Download URL | specux-0.1.0-cp311-cp311-win_amd64.whl |
|---|---|
| Size | 42.8 MB |
| Tags | CPython 3.11 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
fecd70ca86c15dc0729bb2ed1baf779e606acea678a22f6cc3671d66c6fb08b3
|
|
BLAKE2b-256 checksum How to use checksums |
1623de7bbc01b807fa086f5f9cb6d4d293b9cbcae1df019aa5247feaafb941df
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.12
|
Release files / specux-0.1.0-cp311-cp311-manylinux_2_28_x86_64.whl
| Download URL | specux-0.1.0-cp311-cp311-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 43.3 MB |
| Tags | CPython 3.11 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
58cd71667a9a24b55fe97c40c4cc60fd631771e937f86a8e00b46c770198df90
|
|
BLAKE2b-256 checksum How to use checksums |
2fdd91c845daea0a7828b666269bcbe932015d161032f409b91521bf09369adb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.12
|
Release files / specux-0.1.0-cp311-cp311-macosx_11_0_arm64.whl
| Download URL | specux-0.1.0-cp311-cp311-macosx_11_0_arm64.whl |
|---|---|
| Size | 10.2 MB |
| Tags | CPython 3.11 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
fefc3cc14ba32363b17fa58777060a5b4e79a415f1a07d3967d6bba634ad5f94
|
|
BLAKE2b-256 checksum How to use checksums |
e6dc743a7c6b315318609c1691ae54aeca1ce69ab67cc3a938806f85bfdafdba
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.12
|
Release files / specux-0.1.0-cp310-cp310-win_amd64.whl
| Download URL | specux-0.1.0-cp310-cp310-win_amd64.whl |
|---|---|
| Size | 42.8 MB |
| Tags | CPython 3.10 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
f1492ef3d4077952369491f0da44886cd861a858df238053fec24326c330cadf
|
|
BLAKE2b-256 checksum How to use checksums |
467ed13d3386ad5fcc5547fabc484173d6e74ee3bc6d05ee177ec2cdf49320b5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.12
|
Release files / specux-0.1.0-cp310-cp310-manylinux_2_28_x86_64.whl
| Download URL | specux-0.1.0-cp310-cp310-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 43.2 MB |
| Tags | CPython 3.10 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
2cd00bc8249e386052426cb1b6ef618d3412f46b4ec8af8b94007f5cee8ae6ca
|
|
BLAKE2b-256 checksum How to use checksums |
bcd3146ed1b4c9ed376e241577a0e2703c2ef4b096a720a72097131bc678f506
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.12
|
Release files / specux-0.1.0-cp310-cp310-macosx_11_0_arm64.whl
| Download URL | specux-0.1.0-cp310-cp310-macosx_11_0_arm64.whl |
|---|---|
| Size | 10.2 MB |
| Tags | CPython 3.10 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
789d8389f3066e4fdc2776fd595c73d24d8603c27e8633ff07bffc064c4196e6
|
|
BLAKE2b-256 checksum How to use checksums |
8c0d0612774501e3daf43a5a9829951ac87f66890fafdce8b0a7982f3c03d375
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.12
|
Security for specux 0.1.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.