Skip to main content

A Python package for applying convolution reverb to audio files using PyTorch

Project description

Convolution Reverb

A Python package for applying convolution reverb to audio files using PyTorch. This package provides an efficient implementation of convolution reverb using FFT-based convolution.

Installation

Install the package using pip:

pip install convolution-reverb

Requirements

  • Python >= 3.8
  • PyTorch >= 2.0.0
  • torchaudio >= 2.0.0

See requirements.txt.

I think you need sox as well (see https://anaconda.org/conda-forge/sox)

Usage

Basic Usage

from convolution_reverb import apply_reverb
import torchaudio

# Load audio files
audio_path = "path/to/your/audio.wav"
ir_path = "path/to/your/impulse_response.wav"
output_path = "output.wav"

# Apply reverb
original, convolved, sample_rate = apply_reverb(
    audio_path=audio_path,
    ir_path=ir_path,
    output_path=output_path,
)

Working with Tensors Directly

If you're already working with audio tensors in PyTorch:

import torch
import torchaudio
from convolution_reverb import apply_reverb

# Load a sample audio, impulse response
audio_wav, audio_wav_sr = torchaudio.load("path/to/your/audio.wav")
ir_tensor, ir_sr = torchaudio.load("path/to/your/impulse_response.wav")

# Apply reverb
original, convolved, sr = apply_reverb(
    audio_wav=audio_tensor,
    audio_wav_sr=audio_wav_sr,
    ir_wav=ir_tensor,
    ir_wav_sr=ir_sr,
    output_path=output_path,
)

API Reference

apply_reverb

apply_reverb(
    audio_path: Union[str, None] = None,
    audio_wav: Union[torch.Tensor, None] = None,
    audio_wav_sr: Union[int, None] = None,
    ir_path: Union[str, None] = None,
    ir_wav: Union[torch.Tensor, None] = None,
    ir_wav_sr: Union[int, None] = None,
    output_path: Union[str, None] = None,
    use_partitioned: bool = True,
    block_size: Optional[int] = None,
    normalize: bool = False
) -> Tuple[torch.Tensor, torch.Tensor, int]

Parameters:

  • audio_path: Path to the input audio file
  • audio_wav: Input audio as a torch.Tensor (n_channels, n_samples)
  • audio_wav_sr: Sampling rate of the input audio tensor
  • ir_path: Path to the impulse response file
  • ir_wav: Impulse response as a torch.Tensor (n_channels, n_samples)
  • ir_wav_sr: Sampling rate of the impulse response tensor
  • output_path: Path where the output audio will be saved
  • use_partitioned: If True, uses partitioned convolution (overlap‑add) to avoid potential numerical precision issues with large FFT blocks. Recommended for long audio signals.
  • block_size: Block size (in samples) for partitioned convolution. If not provided and use_partitioned is True, defaults to 10 seconds of audio.
  • normalize: Whether to normalize the output audio

Returns:

  • Tuple containing:
    • Original audio waveform (torch.Tensor)
    • Convolved audio waveform (torch.Tensor)
    • Sample rate (int)

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

convolution_reverb-0.1.4.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

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

convolution_reverb-0.1.4-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file convolution_reverb-0.1.4.tar.gz.

File metadata

  • Download URL: convolution_reverb-0.1.4.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.16

File hashes

Hashes for convolution_reverb-0.1.4.tar.gz
Algorithm Hash digest
SHA256 dd56142f2c0defdd6cd8cc463ed1a4e4c2ddac07ac6c669509eb64b8b2d6930e
MD5 2e794a3cad59dc13603de43a7fba83ec
BLAKE2b-256 3707c56eae1d54fb8b5af8902b5073472d52823378ca07d43830e4add0efd365

See more details on using hashes here.

File details

Details for the file convolution_reverb-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for convolution_reverb-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 4e54f3b4efa280e7c0a49352461fb3223d35104d3780c8905f11efbd5f80bf6c
MD5 d59560a71d5dcd698acbb2f33645b77b
BLAKE2b-256 c942575e4a9f5bc08d6e9ad2c768f2d7b6759cf0a96690469690c9fe86719b1f

See more details on using hashes here.

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