Last active
March 7, 2021 09:40
-
-
Save ketanhdoshi/1e288f71a77b01f8c37118c4b502aa93 to your computer and use it in GitHub Desktop.
Transform Change Sampling Rate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ---------------------------- | |
# Since Resample applies to a single channel, we resample one channel at a time | |
# ---------------------------- | |
@staticmethod | |
def resample(aud, newsr): | |
sig, sr = aud | |
if (sr == newsr): | |
# Nothing to do | |
return aud | |
num_channels = sig.shape[0] | |
# Resample first channel | |
resig = torchaudio.transforms.Resample(sr, newsr)(sig[:1,:]) | |
if (num_channels > 1): | |
# Resample the second channel and merge both channels | |
retwo = torchaudio.transforms.Resample(sr, newsr)(sig[1:,:]) | |
resig = torch.cat([resig, retwo]) | |
return ((resig, newsr)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment