lingvo/tasks/asr/frontend.py
def _MelSpectrogram(self, signal):
    """Computes the mel spectrogram from a waveform signal.

    Args:
      signal: f32 Tensor, shaped [batch_size, num_samples]

    Returns:
      features: f32 Tensor, shaped [batch_size, num_frames, mel_channels]
    """
    p = self.params
    # FFT.
    real_frequency_spectrogram = tf.signal.rfft(signal, [self._fft_size])
    magnitude_spectrogram = tf.abs(real_frequency_spectrogram)

    # Shape of magnitude_spectrogram is num_frames x (fft_size/2+1)
    # Mel_weight is [num_spectrogram_bins, num_mel_bins]
    mel_weight_matrix = tf.signal.linear_to_mel_weight_matrix(
        num_mel_bins=p.num_bins,
        num_spectrogram_bins=self._fft_size // 2 + 1,
        sample_rate=p.sample_rate,
        lower_edge_hertz=p.lower_edge_hertz,
        upper_edge_hertz=p.upper_edge_hertz,
        dtype=tf.float32)
    # Weight matrix implemented in the magnitude domain.
    batch_size, num_frames, fft_channels = py_utils.GetShape(
        magnitude_spectrogram, 3)
    mel_spectrogram = tf.matmul(
        tf.reshape(magnitude_spectrogram,
                   [batch_size * num_frames, fft_channels]), mel_weight_matrix)
    mel_spectrogram = tf.reshape(mel_spectrogram,
                                 [batch_size, num_frames, p.num_bins])

    return mel_spectrogram
Computes the mel spectrogram from a waveform signal.

    Args:
      signal: f32 Tensor, shaped [batch_size, num_samples]

    Returns:
      features: f32 Tensor, shaped [batch_size, num_frames, mel_channels]
    
Computes the mel spectrogram from a waveform signal.
Computes the mel spectrogram from a waveform signal .
def _MelSpectrogram(self, signal):
    p = self.params
    real_frequency_spectrogram = tf.signal.rfft(signal, [self._fft_size])
    magnitude_spectrogram = tf.abs(real_frequency_spectrogram)
    mel_weight_matrix = tf.signal.linear_to_mel_weight_matrix(
        num_mel_bins=p.num_bins,
        num_spectrogram_bins=self._fft_size // 2 + 1,
        sample_rate=p.sample_rate,
        lower_edge_hertz=p.lower_edge_hertz,
        upper_edge_hertz=p.upper_edge_hertz,
        dtype=tf.float32)
    batch_size, num_frames, fft_channels = py_utils.GetShape(
        magnitude_spectrogram, 3)
    mel_spectrogram = tf.matmul(
        tf.reshape(magnitude_spectrogram,
                   [batch_size * num_frames, fft_channels]), mel_weight_matrix)
    mel_spectrogram = tf.reshape(mel_spectrogram,
                                 [batch_size, num_frames, p.num_bins])
    return mel_spectrogram
def _MelSpectrogram ( self , signal ) : p = self . params real_frequency_spectrogram = tf . signal . rfft ( signal , [ self . _fft_size ] ) magnitude_spectrogram = tf . abs ( real_frequency_spectrogram ) mel_weight_matrix = tf . signal . linear_to_mel_weight_matrix ( num_mel_bins = p . num_bins , num_spectrogram_bins = self . _fft_size // 2 + 1 , sample_rate = p . sample_rate , lower_edge_hertz = p . lower_edge_hertz , upper_edge_hertz = p . upper_edge_hertz , dtype = tf . float32 ) batch_size , num_frames , fft_channels = py_utils . GetShape ( magnitude_spectrogram , 3 ) mel_spectrogram = tf . matmul ( tf . reshape ( magnitude_spectrogram , [ batch_size * num_frames , fft_channels ] ) , mel_weight_matrix ) mel_spectrogram = tf . reshape ( mel_spectrogram , [ batch_size , num_frames , p . num_bins ] ) return mel_spectrogram
Computes the mel spectrogram from a waveform signal.
Computes the mel spectrogram from a waveform signal .
"""Computes the mel spectrogram from a waveform signal.

    Args:
      signal: f32 Tensor, shaped [batch_size, num_samples]

    Returns:
      features: f32 Tensor, shaped [batch_size, num_frames, mel_channels]
    """ # FFT. # Shape of magnitude_spectrogram is num_frames x (fft_size/2+1) # Mel_weight is [num_spectrogram_bins, num_mel_bins] # Weight matrix implemented in the magnitude domain.
f32 Tensor, shaped [batch_size, num_frames, mel_channels]
f32 Tensor shaped [ batch_size num_frames mel_channels ]
features
self
signal
f32 Tensor, shaped [batch_size, num_samples]
f32 Tensor shaped [ batch_size num_samples ]