def _dft_magnitude(self, signal): """Compute DFT and then its magnitude. It is avoiding tflite incompatible ops. Args: signal: has dims [..., frame_size] Returns: magnitude_spectrogram: with dims [..., fft_size] """ real_spectrum = tf.matmul(signal, self.real_dft_tensor) imag_spectrum = tf.matmul(signal, self.imag_dft_tensor) magnitude_spectrum = tf.add(real_spectrum * real_spectrum, imag_spectrum * imag_spectrum) if self.magnitude_squared: return magnitude_spectrum else: return tf.sqrt(magnitude_spectrum)
def call(self, inputs): if self.use_tf: # compute DCT with tf function output = tf.signal.dct(inputs, type=2, n=self.num_features, norm=None) return output * self.norm else: # compute DCT direct matmul return tf.matmul(inputs, self.dct)
def call(self, inputs): # compute magnitude of fourier spectrum fft_mag = super(MagnitudeRDFTmel, self).call(inputs) # apply mel spectrum if self.use_tf_fft: mel_weight_matrix = tf.signal.linear_to_mel_weight_matrix( num_mel_bins=self.num_mel_bins, num_spectrogram_bins=self.feature_size, sample_rate=self.sample_rate, lower_edge_hertz=self.lower_edge_hertz, upper_edge_hertz=self.upper_edge_hertz, dtype=tf.float32) else: mel_weight_matrix = self.mel_weight_matrix return tf.matmul(fft_mag, mel_weight_matrix)
def call(self, inputs): # Multiply by mel weight matrix (num_spectrogram_bins, num_mel_bins) return tf.matmul(inputs, self.mel_weight_matrix)
def call(self, inputs): # compute DCT return tf.matmul(inputs, self.dct)
def call(self, inputs): # compute magnitude of fourier spectrum fft_mag = super(MagnitudeRDFTmel, self).call(inputs) # apply mel spectrum return tf.matmul(fft_mag, self.mel_weight_matrix)