Ejemplo n.º 1
0
def test_mel_spectrogram_is_equal():
    x = np.random.randn(22050)
    x = np.abs(x) / np.max(np.abs(x))
    mel_npy = logmelfilterbank(
        x,
        22050,
        fft_size=1024,
        hop_size=256,
        win_length=None,
        window="hann",
        num_mels=80,
        fmin=80,
        fmax=7600,
        eps=1e-10,
    )
    mel_spectrogram = MelSpectrogram(
        fs=22050,
        fft_size=1024,
        hop_size=256,
        win_length=None,
        window="hann",
        num_mels=80,
        fmin=80,
        fmax=7600,
        eps=1e-10,
    ).to(dtype=torch.double)
    mel_torch = mel_spectrogram(torch.from_numpy(x).unsqueeze(0))
    np.testing.assert_array_almost_equal(
        mel_npy.transpose(1, 0).astype(np.float32),
        mel_torch[0].numpy().astype(np.float32),
    )
Ejemplo n.º 2
0
 def _analyze_mlfb(self, wavf):
     # read wav file as float format
     x, fs = sf.read(str(wavf))
     self.feats["mlfb"] = logmelfilterbank(
         x,
         self.conf["fs"],
         hop_size=self.conf["hop_size"],
         win_length=self.conf["fftl"],
         window="hann",
         num_mels=self.conf["mlfb_dim"],
         fmin=self.conf["fmin"],
         fmax=self.conf["fmax"],
         eps=EPS,
     )
Ejemplo n.º 3
0
 def _analyze_mlfb(self, wavf):
     # read wav file as float format
     x, fs = sf.read(str(wavf))
     for win_type in self.windows.keys():
         if win_type == "hann":
             feat_name = "mlfb"
         else:
             feat_name = f"mlfb_{win_type}"
         self.feats[feat_name] = logmelfilterbank(
             x,
             self.conf["fs"],
             hop_size=self.conf["hop_size"],
             fft_size=self.conf["fftl"],
             win_length=self.conf["fftl"],
             window=self.windows[win_type],
             num_mels=self.conf["mlfb_dim"],
             fmin=self.conf["fmin"],
             fmax=self.conf["fmax"],
             eps=EPS,
         )