Skip to main content

specux

License: MIT

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 modes complex / magnitude / power / db and configured class twins (specux.STFT, specux.MFCC, ...). specux.transforms adds torch nn.Module wrappers with torchaudio-shaped defaults.
  • FFT family: fft / ifft / rfft / irfft at any length (powers of two, smooth sizes, primes) and precision (float32, float64, and float16 storage with float32 compute), plus reusable plans (fft_plan, stft_plan with optional autotuning).
  • Audio I/O (specux.audio): decode and encode WAV/FLAC/MP3/OGG/MP4, frame-accurate offset/duration, batch load_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.library custom op, so torch.compile(fullgraph=True) traces without graph breaks and torch.autocast computes 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 follows torch.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_HOME overrides); running needs an NVIDIA driver plus NVRTC from a toolkit, torch, or the nvidia-* pip wheels. Skipped with a notice otherwise.
  • CPU: always builds. SPECUX_CPU_ONLY=1 forces 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.ps1 fetches a self-contained LGPL build and scripts/get_taglib.ps1 adds tag/cover support. Without FFmpeg the audio module is skipped and everything else works.
  • Windows: ./scripts/build.ps1 imports 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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

specux-0.1.0.tar.gz (867.6 kB view details)

Uploaded Source

Built Distributions

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

specux-0.1.0-cp313-cp313-win_amd64.whl (42.8 MB view details)

Uploaded CPython 3.13Windows x86-64

specux-0.1.0-cp313-cp313-manylinux_2_28_x86_64.whl (43.5 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

specux-0.1.0-cp313-cp313-macosx_11_0_arm64.whl (10.2 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

specux-0.1.0-cp312-cp312-win_amd64.whl (42.8 MB view details)

Uploaded CPython 3.12Windows x86-64

specux-0.1.0-cp312-cp312-manylinux_2_28_x86_64.whl (43.5 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

specux-0.1.0-cp312-cp312-macosx_11_0_arm64.whl (10.2 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

specux-0.1.0-cp311-cp311-win_amd64.whl (42.8 MB view details)

Uploaded CPython 3.11Windows x86-64

specux-0.1.0-cp311-cp311-manylinux_2_28_x86_64.whl (43.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

specux-0.1.0-cp311-cp311-macosx_11_0_arm64.whl (10.2 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

specux-0.1.0-cp310-cp310-win_amd64.whl (42.8 MB view details)

Uploaded CPython 3.10Windows x86-64

specux-0.1.0-cp310-cp310-manylinux_2_28_x86_64.whl (43.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

specux-0.1.0-cp310-cp310-macosx_11_0_arm64.whl (10.2 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file specux-0.1.0.tar.gz.

File metadata

  • Download URL: specux-0.1.0.tar.gz
  • Upload date:
  • Size: 867.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for specux-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f65e4324a742ebf469e1654770ce0282a4fbb512082ed93cfac2df5cf30e3d26
MD5 015c42f67a365d99e38f5117c99dc7bf
BLAKE2b-256 bffaff776627fe57148ad90d8cdd0e2ca4a97f3a1a288c093e551a058d7b67e6

See more details on using hashes here.

File details

Details for the file specux-0.1.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: specux-0.1.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 42.8 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for specux-0.1.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 7b826a6acf923ad0fd2c0ccd179e8ef3af3a1299cb14e45d35d9beb9cc404acb
MD5 84493b6b047d6ce6ebda72e0e1cd30e3
BLAKE2b-256 5095542187562c9f85cbe45985f251860b5a9337ec61fdb119bc3bff0e0c6d68

See more details on using hashes here.

File details

Details for the file specux-0.1.0-cp313-cp313-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for specux-0.1.0-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c187569090c592cce7c4792f4d2fb200af78e87f9c41c1c97ae5be6f2b3f3f62
MD5 6bea856e220e18cb491ff90ff4b9e17f
BLAKE2b-256 608a70ac392ff5983373a4828a1244ab4be5654b703cd91767ba74814ac0b4a2

See more details on using hashes here.

File details

Details for the file specux-0.1.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for specux-0.1.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6b149da11236ae5b8b5a7b5a9e6e773e63781919a1f8169ff69f600ca9378e66
MD5 9b05855234b9b5168eb850ee7d21b480
BLAKE2b-256 c22870778cf3da439bb03e72ae211e54227b211f0de56ac7f0f040394ccf9f48

See more details on using hashes here.

File details

Details for the file specux-0.1.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: specux-0.1.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 42.8 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for specux-0.1.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 3ae615822ec95f6c85458031d3378a34f73dd0fda7db5dbdd62a6ec5e96eaf39
MD5 a61030750d40f69a30b3771100a72e48
BLAKE2b-256 e5650337663d95bea08776e6e33a6247f817d04c2967229db52fb03baae0ed87

See more details on using hashes here.

File details

Details for the file specux-0.1.0-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for specux-0.1.0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e47fb4f125aa9bafb9c38e2cb160ec2b2b820f724f735fce87384c7f2d21af96
MD5 e4bfa9d8c5314a9fec570acac189de37
BLAKE2b-256 c48ab1684a9a89a39db8a4a8779c0ea21c5d39acd9753d56806c3c43567a512f

See more details on using hashes here.

File details

Details for the file specux-0.1.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for specux-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8f5b3477f342ad29731b9badad3acd36b0e51c999a3df6a117afaf2c32df56b9
MD5 b1ed2ce6659ea3717d34d3066da670f8
BLAKE2b-256 24f1c4a76cd17c33f69a4556f79f99c6cfdc152392b098ddd4d683116e7bdd9f

See more details on using hashes here.

File details

Details for the file specux-0.1.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: specux-0.1.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 42.8 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for specux-0.1.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 fecd70ca86c15dc0729bb2ed1baf779e606acea678a22f6cc3671d66c6fb08b3
MD5 0801561010bcc968db891c6cd40f18c3
BLAKE2b-256 1623de7bbc01b807fa086f5f9cb6d4d293b9cbcae1df019aa5247feaafb941df

See more details on using hashes here.

File details

Details for the file specux-0.1.0-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for specux-0.1.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 58cd71667a9a24b55fe97c40c4cc60fd631771e937f86a8e00b46c770198df90
MD5 e1d0a1f6eef326e567432ea9d9500bbf
BLAKE2b-256 2fdd91c845daea0a7828b666269bcbe932015d161032f409b91521bf09369adb

See more details on using hashes here.

File details

Details for the file specux-0.1.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for specux-0.1.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fefc3cc14ba32363b17fa58777060a5b4e79a415f1a07d3967d6bba634ad5f94
MD5 aaf78485a6e8c405e1325490803aa19a
BLAKE2b-256 e6dc743a7c6b315318609c1691ae54aeca1ce69ab67cc3a938806f85bfdafdba

See more details on using hashes here.

File details

Details for the file specux-0.1.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: specux-0.1.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 42.8 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for specux-0.1.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 f1492ef3d4077952369491f0da44886cd861a858df238053fec24326c330cadf
MD5 0d654f46d1f7410a680c5a462448684d
BLAKE2b-256 467ed13d3386ad5fcc5547fabc484173d6e74ee3bc6d05ee177ec2cdf49320b5

See more details on using hashes here.

File details

Details for the file specux-0.1.0-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for specux-0.1.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2cd00bc8249e386052426cb1b6ef618d3412f46b4ec8af8b94007f5cee8ae6ca
MD5 1e27e84819fbb9a7d392d06ce3c0ba69
BLAKE2b-256 bcd3146ed1b4c9ed376e241577a0e2703c2ef4b096a720a72097131bc678f506

See more details on using hashes here.

File details

Details for the file specux-0.1.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for specux-0.1.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 789d8389f3066e4fdc2776fd595c73d24d8603c27e8633ff07bffc064c4196e6
MD5 241d3db64b12d4bd0f2a7d05b8734888
BLAKE2b-256 8c0d0612774501e3daf43a5a9829951ac87f66890fafdce8b0a7982f3c03d375

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

13 files

0.0.0

2 files

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