Skip to content

Instantly share code, notes, and snippets.

@ketanhdoshi
Last active February 5, 2023 02:40
Show Gist options
  • Save ketanhdoshi/35f19156e18e4cb771564b1c58041594 to your computer and use it in GitHub Desktop.
Save ketanhdoshi/35f19156e18e4cb771564b1c58041594 to your computer and use it in GitHub Desktop.
Transform Mel Spectrogram
# ----------------------------
# Generate a Spectrogram
# ----------------------------
@staticmethod
def spectro_gram(aud, n_mels=64, n_fft=1024, hop_len=None):
sig,sr = aud
top_db = 80
# spec has shape [channel, n_mels, time], where channel is mono, stereo etc
spec = transforms.MelSpectrogram(sr, n_fft=n_fft, hop_length=hop_len, n_mels=n_mels)(sig)
# Convert to decibels
spec = transforms.AmplitudeToDB(top_db=top_db)(spec)
return (spec)
@model586
Copy link

model586 commented Feb 5, 2023

@staticmethod
def spectro_gram(aud, n_mels=64, n_fft=1024, hop_len=None):
sig,sr = aud
top_db = 80

# spec has shape [channel, n_mels, time], where channel is mono, stereo etc
spec = transforms.MelSpectrogram(sr, n_fft=n_fft, hop_length=hop_len, n_mels=n_mels)(sig)

# Convert to decibels
spec = transforms.AmplitudeToDB(top_db=top_db)(spec)
return (spec)

@harthalhmati2000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment