Julius (PyTorch DSP Library)

0.2.7 · active · verified Fri Apr 10

Julius is a Python library providing fast, differentiable Digital Signal Processing (DSP) algorithms implemented with PyTorch, offering CUDA support. It specializes in functionalities like sinc resampling, FFT-based convolutions, and FIR filter banks for audio and 1D signals. The current version is 0.2.7, with releases addressing compatibility and performance improvements.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates the core resampling functionality using `julius.resample_frac` and a basic FFT-based convolution with `julius.fftconv.fft_conv1d`. The resampling function is designed for efficiency when sample rates form a fraction with a small numerator and denominator after GCD reduction.

import julius
import torch

# Create a dummy audio signal (batch_size, channels, time)
signal = torch.randn(2, 1, 44100) # 2 batches, 1 channel, 44100 samples (1 second at 44.1kHz)

old_sample_rate = 44100
new_sample_rate = 16000

# Resample the signal
resampled_signal = julius.resample_frac(signal, old_sr=old_sample_rate, new_sr=new_sample_rate)

print(f"Original signal shape: {signal.shape}")
print(f"Resampled signal shape: {resampled_signal.shape}")
# For FFT-based convolution:
x = torch.randn(1, 1, 2048) # Input (batch, channels, time)
w = torch.randn(1, 1, 512) # Kernel (out_channels, in_channels, kernel_size)
y = julius.fftconv.fft_conv1d(x, w)
print(f"FFT Conv output shape: {y.shape}")

view raw JSON →