Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

SpecuX

License: MIT

Differentiable audio DSP for Python: fast, fused kernels on GPU and CPU.

SpecuX provides FFTs and convolution, spectral transforms and reconstruction, audio features, filtering, and optional audio I/O through one functional API for NumPy, Torch, CuPy, and JAX. Results use the input array library. Resident arrays remain on their device.

Documentation: https://specux.com

import specux
import torch

x = torch.randn(8, 32768, device="cuda", requires_grad=True)
S = specux.stft(x, n_fft=1024, hop_length=256, output="power")
S.mean().backward()

assert S.device == x.device
assert x.grad is not None

Execution model

Array libraries, compute engines, graph bridges, and memory transports are separate concerns:

Layer Implementations Responsibility
Array library NumPy, Torch, CuPy, JAX dtype, allocation, and device discovery
Compute engine CPU, CUDA, Metal, ROCm native kernels, plans, pools, and launch policy
Graph bridge eager, Torch custom ops, XLA FFI tracing, fake shapes, autograd, and VJPs
Transport host, staged, device pointer, MTLBuffer, XLA buffer moving or borrowing storage

backend=None follows the input placement. An explicit backend= may stage a NumPy array through another engine. Resident Torch, CuPy, and JAX arrays are not redirected through the host. Move the array explicitly to change devices. XLA controls JAX placement.

ROCm is represented as a separate engine rather than treated as CUDA: the specux._rocm provider builds the same codegen kernels through HIP and hipRTC. It serves resident PyTorch-ROCm and CuPy-ROCm arrays (whose device type is still reported as cuda) by pointer, and stages NumPy through backend="rocm". PyTorch-ROCm is disambiguated from NVIDIA by torch.version.hip, so a HIP tensor is never routed to the CUDA engine. JAX-on-ROCm runs through the same XLA FFI bridge under the ROCM platform, so a resident JAX array stays on the GPU across jit, vmap, and gradients.

Features

  • FFT and convolution: fft, ifft, rfft, and irfft at power-of-two, smooth, and prime lengths. Direct and FFT convolution support gradients for both operands.
  • Transforms and reconstruction: stft, istft, cqt, vqt, icqt, and griffinlim, with complex, magnitude, power, and dB output modes.
  • Features (specux.feature): mel spectrograms, MFCC, LFCC, chroma, RMS energy, onset strength, Tonnetz, spectral descriptors, deltas, inverse mel projection, and filterbank builders.
  • Filtering (specux.filters): lfilter, filtfilt, differentiable biquad designs, preemphasis, and deemphasis. Signal and coefficient gradients are supported for lfilter.
  • Audio I/O (specux.audio, optional): WAV, FLAC, MP3, OGG, and MP4 decoding and encoding; frame-accurate slicing; batch and streaming I/O; resampling; loudness, true-peak, and loudness-range metering; and metadata.
  • Torch integration: resident eager kernels, torch.library custom ops, analytic adjoints, autocast policies, fake kernels, and torch.compile support. specux.transforms provides nn.Module wrappers.
  • CuPy integration: resident CUDA kernels use the array's device pointer and current stream without host staging.
  • JAX integration: typed XLA FFI on CPU, CUDA, and ROCm, including jax.jit, gradients, and batching. Elementwise dB operations remain fusible JAX expressions. JAX Metal is not supported.

Float16 uses float32 compute by default. Eligible GPU transforms may use native half compute with compute="half". Metal computes in float32 and does not support float64. JAX has no complex32, so half inputs widen to float32.

Install

pip install specux            # NumPy runtime; platform wheels include native engines
pip install specux[torch]     # Torch autograd and compile integration
pip install specux[jax]       # JAX runtime for the typed XLA bridge
pip install specux[cuda]      # Recommended CUDA runtime, currently CUDA 12

pip install specux[cuda11]    # Explicit CUDA 11 runtime
pip install specux[cuda12]    # Explicit CUDA 12 runtime
pip install specux[cuda13]    # Explicit CUDA 13 runtime
pip install specux[rocm]      # AMD HIP runtime and hipRTC (rocm-sdk wheels)

SpecuX uses one CUDA engine for CUDA 11, 12, and 13. The optional extras only install a matching NVRTC compiler and runtime headers. Use cuda for the recommended version or a numbered extra to select one explicitly. cuda remains an alias for cuda12 throughout the SpecuX 0.2 release line. The NVIDIA driver remains a system dependency.

No vendor library is linked: the CUDA driver and NVRTC, and the HIP runtime and hipRTC, are all resolved when an engine is first used. One wheel therefore carries the CPU, CUDA and ROCm engines, installs on a machine with none of them, and binds whichever are present - including both GPU vendors at once. The ROCm engine spans ROCm 6 and 7 from the same binary. AMD publishes the rocm-sdk wheels on its own index rather than PyPI, so specux[rocm] needs --index-url https://rocm.nightlies.amd.com/v2/gfx110X-dgpu/; a system ROCm install needs nothing extra.

specux.available("cuda")   # engine built in AND its runtime installed here
specux.devices()           # [Device(rocm:0 'AMD Radeon RX 7600S' gfx1102), ...]

Torch, CuPy, and JAX integrations are optional. Install the CuPy package that matches your CUDA environment. SpecuX does not choose or install a CuPy runtime. A base installation depends only on NumPy. Release wheels include the XLA bridge but do not install JAX.

Source builds

pip install -e .

An isolated build installs JAX in its temporary build environment to obtain the typed FFI headers. This does not add JAX to the installed runtime requirements. With --no-build-isolation, install JAX in the build environment before using SPECUX_JAX=1.

Useful build controls:

  • SPECUX_JAX=0 omits the XLA bridge; SPECUX_JAX=1 requires it.
  • SPECUX_CUDA=0 / SPECUX_ROCM=0 omit that GPU engine; =1 requires it. Both default to auto (build it when its SDK is found). The XLA bridge follows: it carries handlers for whichever GPU engines were built, and CUDA and ROCm can coexist in one build - they register under different XLA platforms - so a single wheel can serve both.
  • SPECUX_CPU_ONLY=1 builds only the CPU engine.
  • SPECUX_CUDA_HOME=/path/to/cuda selects a CUDA toolkit.
  • SPECUX_AUDIO=0 omits audio I/O; SPECUX_AUDIO=1 requires FFmpeg headers.
  • scripts/build.ps1 loads the MSVC environment and builds in place on Windows.

macOS source builds include the CPU and Metal engines. The Metal engine uses the vendored metal-cpp headers. Audio I/O requires FFmpeg development libraries, with TagLib used for tags and cover art. The DSP package remains usable when the audio extension is omitted.

Usage

NumPy and explicit staging

import numpy as np
import specux

x = np.random.default_rng(0).standard_normal((8, 32768)).astype(np.float32)

S = specux.stft(x, n_fft=1024, hop_length=256, output="power")
y = specux.istft(S, n_fft=1024, hop_length=256, length=x.shape[-1])
C = specux.feature.mfcc(x, sr=16000, n_mfcc=20)

# NumPy uses CPU by default; an explicit engine stages the host array.
S_cuda = specux.stft(x, n_fft=1024, backend="cuda")

Audio I/O

import specux

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("session.flac", 30 * sr, sr=sr, mono=True):
    M = specux.feature.melspectrogram(block, sr=sr)

Torch compile and autocast

import specux
import torch

x = torch.randn(8, 32768, device="cuda")

compiled = torch.compile(
    lambda v: specux.stft(v, n_fft=1024, hop_length=256, output="power"),
    fullgraph=True,
)

with torch.autocast("cuda", torch.float16):
    S = compiled(x)

CuPy resident CUDA

import cupy as cp
import specux

x = cp.random.standard_normal((8, 32768)).astype(cp.float32)
S = specux.stft(x, n_fft=1024, hop_length=256, output="power")

assert isinstance(S, cp.ndarray)
assert S.device.id == x.device.id

SpecuX launches on CuPy's current CUDA stream and keeps inputs, intermediates, and outputs on the device.

JAX JIT and gradients

import jax
import jax.numpy as jnp
import specux

x = jnp.ones((8, 32768), dtype=jnp.float32)

def loss(v):
    return specux.stft(v, n_fft=1024, hop_length=256, output="power").mean()

value, grad = jax.jit(jax.value_and_grad(loss))(x)

Enable jax_enable_x64 before creating arrays when using float64:

jax.config.update("jax_enable_x64", True)

Runtime controls

  • specux.deterministic(True) selects reproducible overlap-add kernels and follows torch.use_deterministic_algorithms for Torch callers.
  • specux.set_autotune(True) tunes new GPU configurations and persists launch wisdom.
  • specux.autotune(...) explicitly tunes one operation and configuration.
  • specux.clear_cache() releases clearable Python caches, native plans, and device tables.
  • specux.clear_wisdom() removes persisted launch wisdom.

Design

SpecuX fuses framing, FFT, and output work when supported by the engine and transform shape. Multi-stage operations remain on the same device and stream, without intermediate copies through Python or host memory.

CUDA and Metal kernels share operation definitions through the accelerator code generator. The CPU engine implements the same operation families with AVX2 and NEON SIMD paths. Immutable windows, filterbanks, bases, and FFT data live in bounded native plans. SpecuX resolves those plans behind the functional API.

Torch integration uses a Python custom-op bridge, so the native engines do not depend on the libtorch ABI. CuPy passes resident buffers and the current stream directly to the CUDA engine. JAX integration uses a separate XLA FFI module, so JAX remains optional at runtime.

Native source layout and layering rules are documented in the native source guide.

Development

python scripts/lint.py
python -m pytest tests
python bench/bench_matrix.py

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.2.0.dev0.tar.gz (1.2 MB view details)

Uploaded Source

Built Distributions

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

specux-0.2.0.dev0-cp313-cp313-win_amd64.whl (12.6 MB view details)

Uploaded CPython 3.13Windows x86-64

specux-0.2.0.dev0-cp313-cp313-manylinux_2_28_x86_64.whl (95.4 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

specux-0.2.0.dev0-cp313-cp313-macosx_11_0_arm64.whl (12.1 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

specux-0.2.0.dev0-cp312-cp312-win_amd64.whl (12.6 MB view details)

Uploaded CPython 3.12Windows x86-64

specux-0.2.0.dev0-cp312-cp312-manylinux_2_28_x86_64.whl (95.5 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

specux-0.2.0.dev0-cp312-cp312-macosx_11_0_arm64.whl (12.1 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

specux-0.2.0.dev0-cp311-cp311-win_amd64.whl (12.6 MB view details)

Uploaded CPython 3.11Windows x86-64

specux-0.2.0.dev0-cp311-cp311-manylinux_2_28_x86_64.whl (95.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

specux-0.2.0.dev0-cp311-cp311-macosx_11_0_arm64.whl (12.1 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

specux-0.2.0.dev0-cp310-cp310-win_amd64.whl (12.6 MB view details)

Uploaded CPython 3.10Windows x86-64

specux-0.2.0.dev0-cp310-cp310-manylinux_2_28_x86_64.whl (94.8 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

specux-0.2.0.dev0-cp310-cp310-macosx_11_0_arm64.whl (12.1 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file specux-0.2.0.dev0.tar.gz.

File metadata

  • Download URL: specux-0.2.0.dev0.tar.gz
  • Upload date:
  • Size: 1.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for specux-0.2.0.dev0.tar.gz
Algorithm Hash digest
SHA256 c4391c627336c51d5b491804998387f9bbcd4c5c52f78bf5fbc825d184688cb0
MD5 696212cd7152f3c932396c1545e47a38
BLAKE2b-256 b71453bd5fd41643100361773265762456a2afcd221a1ecdfc1286f3913f11e6

See more details on using hashes here.

File details

Details for the file specux-0.2.0.dev0-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for specux-0.2.0.dev0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 5c616cdb68d2deceeef0b7fe15009ac215fb37a1fb9e8718605e1a456f1a388d
MD5 499b9658d92d248d00290e11948c2f8f
BLAKE2b-256 f3423b06afdd771eb4da8d79cbf436710464f1e9352c14604f3537c987115c87

See more details on using hashes here.

File details

Details for the file specux-0.2.0.dev0-cp313-cp313-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for specux-0.2.0.dev0-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d15ddfb6cd0d1230f890d722fdcd001d47412f75ff02170142aade3e797c010f
MD5 4534c7192d59af7cea4f9d435826b841
BLAKE2b-256 1055980fb135ffd09d144ca745aead0a2f0a9531ac23d709a12489e80eb3c06a

See more details on using hashes here.

File details

Details for the file specux-0.2.0.dev0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for specux-0.2.0.dev0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 672ffdf97aea7f5f7e759aa9a875bbf98f307551ff360dcf5417b36a406ddba2
MD5 2ac2ee33f9539c37ac8ca49747c4fe84
BLAKE2b-256 11fe4e008cc7e47f1d9f584c5f59858e4b2b26470ac585400801cda334315050

See more details on using hashes here.

File details

Details for the file specux-0.2.0.dev0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for specux-0.2.0.dev0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 f46d43c70674c1036bef97974a98c56146094db66bc2f98970e778e9fc2888a9
MD5 5114ad14a7e0e1d5d0753a563cff44f9
BLAKE2b-256 113fda2712aaa0dd3cfb503fc3ed3e1eb53834b7ada9f771bb710f3b48020bb2

See more details on using hashes here.

File details

Details for the file specux-0.2.0.dev0-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for specux-0.2.0.dev0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 58a304a7696c8a78e572c5e1efbfa1a7f8c472329b82287615a6a567d87133dd
MD5 f7d26b26b29eec3102e271a37a1b9e81
BLAKE2b-256 203ccd9f1d1a36bdbef4f29c578dbb56e199ef765c2a007cc74b6b0fe3c854a1

See more details on using hashes here.

File details

Details for the file specux-0.2.0.dev0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for specux-0.2.0.dev0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 26cb0a736a9f4bdd77e5205e165ac53b54ab41ba7d975ad40282c9da9034acad
MD5 a80b51253fb8e106cb10d7c3c949eadf
BLAKE2b-256 b9d5a57dfdf2ae5d9ef6fba24fbb8c38fd6a1d42876ae42b0cb027700176757c

See more details on using hashes here.

File details

Details for the file specux-0.2.0.dev0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for specux-0.2.0.dev0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 07ba5da6af60d34739da3490ae5b2070f2f38c1cf4d584639baca514f7531ec0
MD5 90d86f4ffc0faf97114e882e92e31e37
BLAKE2b-256 c36d4d16fb8640e83d7a6e0608a4ddf2027a87d8056db3b1484ee079f6a65f86

See more details on using hashes here.

File details

Details for the file specux-0.2.0.dev0-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for specux-0.2.0.dev0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4ff47c5e40d345438c73406b82cbe1d0c95a90da529e03aa2b241e0ec690d161
MD5 74e122286de01b909c9ac8dfaf141484
BLAKE2b-256 e9e23ee798caa1614a93a2102ee5f16776e6260b5527a43c40ab7e8528ce3064

See more details on using hashes here.

File details

Details for the file specux-0.2.0.dev0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for specux-0.2.0.dev0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 879f198c12c1c5806cf004cac2ea0b13e9ad18247266ce3d4492824343e3551b
MD5 465ff30ca14328f92f196b355d88f401
BLAKE2b-256 c5ed524b361f3f87e47b6b344a43b86998bf60d6f350fd1b608a56ebdf9999b1

See more details on using hashes here.

File details

Details for the file specux-0.2.0.dev0-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for specux-0.2.0.dev0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 5966021ffd38a9fdabfc899a8a8a0cdef961df061d4dbbe45469953785e1b283
MD5 093e5da8983a410477e2705c0d3c2d12
BLAKE2b-256 fd146b18c32b6506461732d9feef8c657422fd8cbe9081def1b548a966846791

See more details on using hashes here.

File details

Details for the file specux-0.2.0.dev0-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for specux-0.2.0.dev0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a1e12c0d8b8950b2717c46bc13421a94344046b7e4a3d0a1500ff83318bd695b
MD5 148ca26dc4b2dd2194538bf507c3bb32
BLAKE2b-256 911c5a10e96a20b4cbe2861ec15970a09c1de7eb0fcb9f3d80a400c647ca4b54

See more details on using hashes here.

File details

Details for the file specux-0.2.0.dev0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for specux-0.2.0.dev0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7e69c2cdf7f5f9410e7d867cadf1359546b9d04ee04453256fe505d3340df89c
MD5 7c507a35aba61acb4621e1e931563517
BLAKE2b-256 66a412a1e857c1e750cd20128930c8a1ba8e186048570cc48c5e358b182511a3

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.0.dev0 This release

13 files

0.1.0

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