Reshaping mel-spectrogram and chaning n_mels channels

408 views
Skip to first unread message

Bhanu Teja

unread,
Mar 15, 2022, 4:16:52 AM3/15/22
to librosa

I have a mel-spectrogram with (460,80) shape.

460 length and 80 channels

Now I want to convert that mel into (460,40) how can this be achieved using librosa?

Vincent Lostanlen

unread,
Mar 15, 2022, 5:02:45 AM3/15/22
to Bhanu Teja, librosa
Hello,

Just set n_mels=40 in the call to melspectrogram


it will be passed to mel




I hope it helps

Vincent


--
You received this message because you are subscribed to the Google Groups "librosa" group.
To unsubscribe from this group and stop receiving emails from it, send an email to librosa+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/librosa/9c5f0e0c-99c9-4b15-89fc-93d956a1d184n%40googlegroups.com.

Bhanu Teja

unread,
Mar 15, 2022, 11:18:52 AM3/15/22
to librosa
Hello,

The problem is I don't have a source wav file. I have a mel with 80 channels and I wanted to convert it to mel with 40 channels by interpolation or something. 

Vincent Lostanlen

unread,
Mar 15, 2022, 12:35:45 PM3/15/22
to Bhanu Teja, librosa

Bhanu Teja

unread,
Mar 15, 2022, 12:39:14 PM3/15/22
to librosa
Hey  Vincent,

Thanks for looking in this thread. Yes, I tried that as well. My only concern is those 80d values are in mel space so I'm not sure if I can do that. Just wanted to check here if someone tried to do the same here. 

Thanks,
Bhanu

Vincent Lostanlen

unread,
Mar 15, 2022, 12:50:44 PM3/15/22
to Bhanu Teja, librosa
For a 2x interpolation, i guess this is acceptable.

If you want to be more precise about it, and know all the hyperparameters that came into the design of the 80-band mel-spectrogram, you can give mel_to_stft a try



Followed by librosa.feature.melspectrogram with n_mels=40



Sincerely,

Vincent


Brian McFee

unread,
Mar 15, 2022, 12:58:48 PM3/15/22
to librosa
You could also just use a scipy.interpolate.interp1d with mel_frequencies(n_mels=80) as the input positions and mel_frequencies(n_mels=40) as the output positions.  It won't be exactly correct since the filter bandwidths are going to be way off, but depending on your application it might be okay.
Reply all
Reply to author
Forward
0 new messages