Skip to main content

A comprehensive Python toolbox for audio processing using PyTorch with device-aware operations and GPU acceleration.

Project description

VoxLab

A comprehensive Python toolbox for audio processing using PyTorch. VoxLab provides a clean, device-aware architecture for audio manipulation with PyTorch tensors and supports GPU acceleration.

Features

  • Device-Aware Audio Processing: CPU/GPU operations with automatic device preservation
  • Memory-Efficient Operations: In-place processing options to reduce memory usage
  • Comprehensive Preprocessing Pipeline: Resampling, mono conversion, silence removal, chunking, and RMS normalization
  • Extensive Testing: 62 passing tests covering all functionality

Installation

CUDA Installation (Recommended)

# Create conda environment with Python 3.11.13
conda create -n voxlab python=3.11.13 -y
conda activate voxlab

# Install PyTorch with CUDA 12.6 support
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126

# Install in editable mode
pip install -e .

CPU-Only Installation

# For CPU-only usage (no CUDA)
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
pip install -e .

Quick Start

Basic Audio Processing

from voxlab.core.audio_samples import AudioSamples
from voxlab.preprocessing.functions import resample_audio, convert_to_mono

# Load and process audio
audio = AudioSamples.load("input.wav")
audio = resample_audio(audio, 16000, inplace=True)  # Memory efficient
audio = convert_to_mono(audio, method='left', inplace=True)
audio.export("output.wav")

GPU-Accelerated Workflow

# Move to GPU for processing
audio = AudioSamples.load("input.wav").cuda()
print(f"Audio device: {audio.device}")  # cuda:0

# All operations preserve GPU device
audio = resample_audio(audio, 16000, inplace=True)  # Stays on GPU
audio = normalize_audio_rms(audio, target_rms=-20, inplace=True)  # Stays on GPU

Pipeline Processing

from voxlab.preprocessing.pipeline import PreprocessingPipeline
from voxlab.preprocessing.functions import *

# Create pipeline
pipeline = PreprocessingPipeline()
pipeline.add_step(resample_audio, new_sample_rate=16000)
pipeline.add_step(convert_to_mono, method='left')
pipeline.add_step(normalize_audio_rms, target_rms=-15)

# Process (maintains device throughout)
audio = AudioSamples.load("input.wav").cuda()
result = pipeline.process(audio)  # Result stays on GPU

Core Components

AudioSamples Class

  • Central data structure using PyTorch tensors
  • Device-aware operations (.cuda(), .cpu(), .to())
  • Automatic format conversions and stereo handling
  • Export to multiple formats (wav, mp3, ogg, flac)

Preprocessing Functions

  • resample_audio(): Device-preserving resampling with configurable sample rates
  • convert_to_mono(): Stereo-to-mono conversion with channel selection
  • remove_silence(): Intelligent silence removal with fade transitions
  • break_into_chunks(): Audio segmentation with fade-in/fade-out
  • normalize_audio_rms(): RMS-based normalization to target dB levels

Testing

Run tests using pytest:

source venv/bin/activate  # or conda activate voxlab
pytest tests/ -v

Current Status: ✅ 62 tests passing

  • AudioSamples core functionality (11 tests)
  • Device awareness and GPU operations (12 tests)
  • Preprocessing functions (23 tests)
  • Pipeline system (11 tests)
  • Utilities and infrastructure (5 tests)

Requirements

Core Dependencies

  • Python >= 3.11.13
  • PyTorch >= 2.8.0 (with torchaudio)
  • scipy >= 1.16.2
  • numpy >= 2.1.2
  • pytest >= 8.4.2 (for testing)

License

MIT License

Author

Rafaello Virgilli (rvirgilli@gmail.com)

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

voxlab-0.3.0.tar.gz (18.8 kB view details)

Uploaded Source

Built Distribution

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

voxlab-0.3.0-py3-none-any.whl (21.4 kB view details)

Uploaded Python 3

File details

Details for the file voxlab-0.3.0.tar.gz.

File metadata

  • Download URL: voxlab-0.3.0.tar.gz
  • Upload date:
  • Size: 18.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for voxlab-0.3.0.tar.gz
Algorithm Hash digest
SHA256 3b2476fceebe09c82fecf8c210390e7a8e7e127df91f59ea34fa96fb5223372f
MD5 26978b30c8b7e77bd1a456f131ae210c
BLAKE2b-256 297800b53a04c60c278b512a5cdd1fe734411ad0697fc5db1a428c92e32a8ccc

See more details on using hashes here.

File details

Details for the file voxlab-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: voxlab-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 21.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for voxlab-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f44c5a48fef7bfdce440a51c5db82a31d9a55926a9435f6de508c0d98bc843ec
MD5 e72577d49eaf713b564a12da0ebb4cbe
BLAKE2b-256 5192053569117fe93e000497341bda580a1eab80b9f3f19a51299223d06be8c3

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