Skip to content

Instantly share code, notes, and snippets.

@amiasato
amiasato / pitchshift.py
Created July 1, 2021 19:48
Pitch shift script with Pytorch and torch_audiomentations Audio interface
import torch
from torch.nn import functional as F
from torch_audiomentations.utils.io import Audio
import soundfile as sf
# Change this for whatever file you wish
input_path = "test_fixtures/perfect-alley1.ogg"
output_path = "shifted.wav"
import torch
import torch.nn as nn
import torch.nn.functional as F
def lengths_to_mask(lengths, max_len=None, dtype=None):
"""
Converts a "lengths" tensor to its binary mask representation.
Based on: https://discuss.pytorch.org/t/how-to-generate-variable-length-mask/23397