(waveform_input,
                                sample_rate=16000,
                                window_length_seconds=0.025,
                                hop_length_seconds=0.010,
                                num_mel_bins=64,
                                lower_edge_hz=125.0,
                                upper_edge_hz=7500.0,
                                frame_width=96,
                                frame_hop=10,
                                tflite_compatible=False)
return features
Build a TF graph to go from waveform to mel spectrum patches.

  Args:
    waveform_input: 1D Tensor which will be filled with 16 kHz waveform as
      tf.float32.
    sample_rate: Scalar giving the sampling rate of the waveform.  Only 16 kHz
      is acceptable at present.
    window_length_seconds: Duration of window used for each Fourier transform.
    hop_length_seconds: Time shift between successive analysis time frames.
    num_mel_bins: The number of mel frequency bins to calculate.
    lower_edge_hz: Frequency boundary at bottom edge of mel mapping.
    upper_edge_hz: Frequency boundary at top edge of mel mapping.
    frame_width: The number of successive time frames to include in each patch.
    frame_hop: The frame advance between successive patches.
    tflite_compatible: Avoid ops not currently supported in tflite.

  Returns:
    Tensor holding [num_patches, frame_width, num_mel_bins] log-mel-spectrogram
    patches.
Build a TF graph to go from waveform to mel spectrum patches.
Build a TF graph to go from waveform to mel spectrum patches .
def build_mel_calculation_graph(waveform_input,
                                sample_rate=16000,
                                window_length_seconds=0.025,
                                hop_length_seconds=0.010,
                                num_mel_bins=64,
                                lower_edge_hz=125.0,
                                upper_edge_hz=7500.0,
                                frame_width=96,
                                frame_hop=10,
                                tflite_compatible=False):
  """Build a TF graph to go from waveform to mel spectrum patches.

  Args:
    waveform_input: 1D Tensor which will be filled with 16 kHz waveform as
      tf.float32.
    sample_rate: Scalar giving the sampling rate of the waveform.  Only 16 kHz
      is acceptable at present.
    window_length_seconds: Duration of window used for each Fourier transform.
    hop_length_seconds: Time shift between successive analysis time frames.
    num_mel_bins: The number of mel frequency bins to calculate.
    lower_edge_hz: Frequency boundary at bottom edge of mel mapping.
    upper_edge_hz: Frequency boundary at top edge of mel mapping.
    frame_width: The number of successive time frames to include in each patch.
    frame_hop: The frame advance between successive patches.
    tflite_compatible: Avoid ops not currently supported in tflite.

  Returns:
    Tensor holding [num_patches, frame_width, num_mel_bins] log-mel-spectrogram
    patches.
  """
  # `waveform_input` is a [?] vector as a tensor.
  # `magnitude_spectrogram` is a [?, fft_length/2 + 1] tensor of spectrograms.
  # Derive the dependent parameters.
  window_length_samples = int(round(window_length_seconds * sample_rate))
  hop_length_samples = int(round(hop_length_seconds * sample_rate))
  fft_length = 2**int(
      math.ceil(math.log(window_length_samples) / math.log(2.0)))
  if tflite_compatible:
    magnitude_spectrogram = _stft_magnitude_tflite(
        waveform_input, window_length_samples, hop_length_samples, fft_length)
  else:
    magnitude_spectrogram = _stft_magnitude_full_tf(
        waveform_input, window_length_samples, hop_length_samples, fft_length)

  # Warp the linear-scale, magnitude spectrograms into the mel-scale.
  num_spectrogram_bins = int(magnitude_spectrogram.shape[-1])
  if tflite_compatible:
    linear_to_mel_weight_matrix = tf.constant(
        mfcc_mel.SpectrogramToMelMatrix(num_mel_bins, num_spectrogram_bins,
                                        sample_rate, lower_edge_hz,
                                        upper_edge_hz).astype(np.float32),
        name='linear_to_mel_matrix')
  else:
    # In full tf, the mel weight matrix is calculated at run time within the
    # TF graph.  This avoids including a matrix of 64 x 256 float values (i.e.,
    # 100 kB or more, depending on the representation) in the exported graph.
    linear_to_mel_weight_matrix = tf.signal.linear_to_mel_weight_matrix(
        num_mel_bins, num_spectrogram_bins, sample_rate, lower_edge_hz,
        upper_edge_hz)

  mel_spectrogram = tf.matmul(
      magnitude_spectrogram,
      linear_to_mel_weight_matrix,
      name='mel_spectrogram')
  log_offset = 0.001
  log_mel_spectrogram = tf.log(
      mel_spectrogram + log_offset, name='log_mel_spectrogram')
  # log_mel_spectrogram is a [?, num_mel_bins] gram.
  if tflite_compatible:
    features = _fixed_frame(
        log_mel_spectrogram,
        frame_length=frame_width,
        frame_step=frame_hop,
        first_axis=True)
  else:
    features = tf.signal.frame(
        log_mel_spectrogram,
        frame_length=frame_width,
        frame_step=frame_hop,
        axis=0)
  # features is [num_patches, frame_width, num_mel_bins].
  return features
def build_mel_calculation_graph ( waveform_input , sample_rate = 16000 , window_length_seconds = 0.025 , hop_length_seconds = 0.010 , num_mel_bins = 64 , lower_edge_hz = 125.0 , upper_edge_hz = 7500.0 , frame_width = 96 , frame_hop = 10 , tflite_compatible = False ) : # `waveform_input` is a [?] vector as a tensor. # `magnitude_spectrogram` is a [?, fft_length/2 + 1] tensor of spectrograms. # Derive the dependent parameters. window_length_samples = int ( round ( window_length_seconds * sample_rate ) ) hop_length_samples = int ( round ( hop_length_seconds * sample_rate ) ) fft_length = 2 ** int ( math . ceil ( math . log ( window_length_samples ) / math . log ( 2.0 ) ) ) if tflite_compatible : magnitude_spectrogram = _stft_magnitude_tflite ( waveform_input , window_length_samples , hop_length_samples , fft_length ) else : magnitude_spectrogram = _stft_magnitude_full_tf ( waveform_input , window_length_samples , hop_length_samples , fft_length ) # Warp the linear-scale, magnitude spectrograms into the mel-scale. num_spectrogram_bins = int ( magnitude_spectrogram . shape [ - 1 ] ) if tflite_compatible : linear_to_mel_weight_matrix = tf . constant ( mfcc_mel . SpectrogramToMelMatrix ( num_mel_bins , num_spectrogram_bins , sample_rate , lower_edge_hz , upper_edge_hz ) . astype ( np . float32 ) , name = 'linear_to_mel_matrix' ) else : # In full tf, the mel weight matrix is calculated at run time within the # TF graph.  This avoids including a matrix of 64 x 256 float values (i.e., # 100 kB or more, depending on the representation) in the exported graph. linear_to_mel_weight_matrix = tf . signal . linear_to_mel_weight_matrix ( num_mel_bins , num_spectrogram_bins , sample_rate , lower_edge_hz , upper_edge_hz ) mel_spectrogram = tf . matmul ( magnitude_spectrogram , linear_to_mel_weight_matrix , name = 'mel_spectrogram' ) log_offset = 0.001 log_mel_spectrogram = tf . log ( mel_spectrogram + log_offset , name = 'log_mel_spectrogram' ) # log_mel_spectrogram is a [?, num_mel_bins] gram. if tflite_compatible : features = _fixed_frame ( log_mel_spectrogram , frame_length = frame_width , frame_step = frame_hop , first_axis = True ) else : features = tf . signal . frame ( log_mel_spectrogram , frame_length = frame_width , frame_step = frame_hop , axis = 0 ) # features is [num_patches, frame_width, num_mel_bins]. return features