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.
pip install torch-pitch-shiftVerified import paths — ran on the pinned version, not inferred.
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`).
Upgrade to `torch-pitch-shift>=1.2.2` and ensure `torchaudio` is within a compatible range, or explicitly manage `torchaudio` version based on `torch-pitch-shift` release notes.
Upgrade to `torch-pitch-shift>=1.2.0` and consider utilizing the `hop_length` argument for better results.
Review the `sample_rate` and the `validate_fn` (transpose range) arguments passed to `get_fast_shifts`. Adjust the range or accept that not all desired shifts may be 'fast' for specific audio characteristics.
Be aware of this characteristic if deploying in highly secure or constrained environments. Review the source code for specific `eval()` usages if concerns arise.
Prioritize GPU usage for performance-critical applications. If CPU usage is unavoidable, profile your code and consider batching operations to mitigate slowdowns.
Install the library using pip: `pip install torch-pitch-shift`
Ensure all input tensors are explicitly moved to the same device (e.g., `'cuda'` or `'cpu'`) as the `torch_pitch_shift` operation, using `.to('cuda')` or `.to(device)`.Cast the `shift_val` tensor to a floating-point type, for example, by adding `.float()` or ensuring its initial creation uses float values: `torch.tensor([2.0])`.
Reshape the input audio tensor to explicitly include a channel dimension, typically `(batch_size, 1, time_samples)` for mono audio, using `tensor.unsqueeze(1)` if your `tensor` is `(batch_size, time_samples)`.