示例#1
0
def test_mel(sample_rate, n_freq, n_mels, f_min, f_max_ratio, htk, norm):
    f_max = int(f_max_ratio * (sample_rate // 2))
    mel_fb = KPB.filterbank_mel(
        sample_rate=sample_rate,
        n_freq=n_freq,
        n_mels=n_mels,
        f_min=f_min,
        f_max=f_max,
        htk=htk,
        norm=norm,
    )
    mel_fb = mel_fb.numpy()

    mel_fb_ref = librosa.filters.mel(
        sr=sample_rate,
        n_fft=(n_freq - 1) * 2,
        n_mels=n_mels,
        fmin=f_min,
        fmax=f_max,
        htk=htk,
        norm=norm,
    ).T

    assert mel_fb.dtype == K.floatx()
    assert mel_fb.shape == (n_freq, n_mels)
    np.testing.assert_allclose(mel_fb_ref, mel_fb)
示例#2
0
    def build(self, input_shape):
        if self.image_data_format == 'channels_first':
            self.n_ch = input_shape[1]
            self.n_freq = input_shape[2]
            self.n_time = input_shape[3]
        else:
            self.n_ch = input_shape[3]
            self.n_freq = input_shape[1]
            self.n_time = input_shape[2]

        if self.init == 'mel':
            self.filterbank = K.variable(backend.filterbank_mel(sr=self.sr,
                                                                n_freq=self.n_freq,
                                                                n_mels=self.n_fbs,
                                                                fmin=self.fmin,
                                                                fmax=self.fmax).transpose(),
                                         dtype=K.floatx())
        elif self.init == 'log':
            self.filterbank = K.variable(backend.filterbank_log(sr=self.sr,
                                                                n_freq=self.n_freq,
                                                                n_bins=self.n_fbs,
                                                                bins_per_octave=self.bins_per_octave,
                                                                fmin=self.fmin).transpose(),
                                         dtype=K.floatx())

        if self.trainable_fb:
            self.trainable_weights.append(self.filterbank)
        else:
            self.non_trainable_weights.append(self.filterbank)
        super(Filterbank, self).build(input_shape)
        self.built = True
示例#3
0
def test_filterbank_mel():
    """test for backend.filterbank_mel"""
    fbmel_ref = np.load(
        os.path.join(os.path.dirname(__file__), 'fbmel_8000_512.npy'))
    fbmel = KPB.filterbank_mel(sr=8000, n_freq=512)
    assert fbmel.shape == fbmel_ref.shape
    assert np.allclose(fbmel, fbmel_ref, atol=TOL)