Skip to content

Instantly share code, notes, and snippets.

@ketanhdoshi
Last active March 7, 2021 09:38
Show Gist options
  • Save ketanhdoshi/cb774c0b95277b570e9aeffa78c49889 to your computer and use it in GitHub Desktop.
Save ketanhdoshi/cb774c0b95277b570e9aeffa78c49889 to your computer and use it in GitHub Desktop.
Transform Adjust Number of Channels
# ----------------------------
# 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