Torch Pitch Shift

1.2.5 · active · verified Fri Apr 10

torch-pitch-shift is a Python library that enables rapid pitch-shifting of audio clips using PyTorch, with full CUDA support. It also provides utilities for calculating efficient pitch-shift targets, which is particularly useful for augmentation scenarios where speed is prioritized over precise pitch-shifts. The library is currently at version 1.2.5 and maintains an active development and release cadence.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to generate a dummy audio waveform, apply a pitch shift of 3 semitones using the `pitch_shift` function, and print the resulting tensor shape. In a practical application, `waveform` would be loaded from an audio file (e.g., using `torchaudio.load`).

import torch
from torch_pitch_shift import pitch_shift

# Create a dummy mono audio waveform (batch_size, channels, samples)
sample_rate = 44100
duration_seconds = 2
num_samples = sample_rate * duration_seconds
waveform = torch.randn(1, 1, num_samples, dtype=torch.float32)

# Define the pitch shift amount in semitones
shift_semitones = 3.0 # Shift up by 3 semitones

# Perform the pitch shift
pitch_shifted_waveform = pitch_shift(waveform, shift_semitones, sample_rate)

print(f"Original waveform shape: {waveform.shape}")
print(f"Pitch-shifted waveform shape: {pitch_shifted_waveform.shape}")
# In a real scenario, you would now save or play 'pitch_shifted_waveform'

view raw JSON →