code: def stft_tflite(
      signal, frame_length, frame_step, fft_length, window_fn, pad_end
  ):
      """tflite-compatible implementation of tf.signal.stft.
      Compute the short-time Fourier transform of a 1D input while avoiding tf ops
      that are not currently supported in tflite (Rfft, Range, SplitV).
      fft_length must be fixed. A Hann window is of frame_length is always
      applied.
      Since fixed (precomputed) framing must be used, signal.shape[-1] must be a
      specific value (so "?"/None is not supported).
  
      Args:
          signal: 1D tensor containing the time-domain waveform to be transformed.
          frame_length: int, the number of points in each Fourier frame.
          frame_step: int, the number of samples to advance between successive frames.
          fft_length: int, the size of the Fourier transform to apply.
          window_fn: tf.signal.window, the return of backend.get_window_fn(window_name)
          pad_end: bool, if true pads the end with zeros so that signal contains
              an integer number of frames
  
      Returns:
          spectrogram: Two (num_frames, fft_length) tensors containing the real and
              imaginary parts of the short-time Fourier transform of the input signal.
      """
      signal = tf.cast(signal, tf.float32)
      if pad_end:
          # the number of whole frames
          # (NOTE: kenders2000), padding is pre-calculated and thus fixed in graph
          length_samples = signal.shape[-1]
          num_steps_round_up = int(np.ceil(length_samples / frame_step))
          pad_amount = (
              num_steps_round_up * frame_step
              + frame_length
              - frame_step
          ) - length_samples
          signal = tf.pad(
              signal, tf.constant([[0, 0], [0, 0], [0, pad_amount]])
          )
      # Make the window be shape (1, frame_length) instead of just frame_length
      # in an effort to help the tflite broadcast logic.
      window = tf.reshape(window_fn(frame_length), [1, frame_length])
  
      framed_signal = fixed_frame(signal, frame_length, frame_step)
      framed_signal *= window
  
      spectrogram = _rdft(framed_signal, fft_length)
  
      return spectrogram
  
file_path: kapre/kapre/tflite_compatible_stft.py
imports: import math
  import tensorflow
  import numpy
label_desc: Use image node_id 4 for calling a global function with example usage: stft_tflite(signal, frame_length, frame_step, fft_length, window_fn, pad_end) and returns: spectrogram