Last active
March 7, 2021 09:38
-
-
Save ketanhdoshi/cb774c0b95277b570e9aeffa78c49889 to your computer and use it in GitHub Desktop.
Transform Adjust Number of Channels
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
# ---------------------------- | |
# Convert the given audio to the desired number of channels | |
# ---------------------------- | |
@staticmethod | |
def rechannel(aud, new_channel): | |
sig, sr = aud | |
if (sig.shape[0] == new_channel): | |
# Nothing to do | |
return aud | |
if (new_channel == 1): | |
# Convert from stereo to mono by selecting only the first channel | |
resig = sig[:1, :] | |
else: | |
# Convert from mono to stereo by duplicating the first channel | |
resig = torch.cat([sig, sig]) | |
return ((resig, sr)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment