code: def fixed_frame(signal, frame_length, frame_step):
      """tflite-compatible tf.signal.frame for fixed-size input.
  
      Args:
          signal: Tensor containing signal(s).
          frame_length: Number of samples to put in each frame.
          frame_step: Sample advance between successive frames.
  
      Returns:
          A new tensor where the last axis (or first, if first_axis) of input
          signal has been replaced by a (num_frames, frame_length) array of individual
          frames where each frame is drawn frame_step samples after the previous one.
  
      Raises:
          ValueError: if signal has an undefined axis length.  This routine only
          supports framing of signals whose shape is fixed at graph-build time.
      """
      signal_shape = list(signal.shape)
      length_samples = signal_shape[-1]
  
      if length_samples <= 0:
          raise ValueError(
              "fixed framing requires predefined constant signal length"
          )
      # the number of whole frames
      num_frames = max(
          0, 1 + (length_samples - frame_length) // frame_step
      )
  
      # define the output_shape, if we receive a None dimension, replace with 1
      outer_dimensions = [
          dim if dim else 1 for dim in signal_shape[:-1]
      ]
      # outer_dimensions = signal_shape[:-1]
      output_shape = outer_dimensions + [num_frames, frame_length]
  
      # Currently tflite's gather only supports axis==0, but that may still
      # work if we want the last of 1 axes.
      gather_axis = len(outer_dimensions)
  
      # subframe length is the largest int that as a common divisor of the frame
      # length and hop length. We will slice the signal up into these subframes
      # in order to then construct the frames.
      subframe_length = math.gcd(frame_length, frame_step)
      subframes_per_frame = frame_length // subframe_length
      subframes_per_hop = frame_step // subframe_length
      num_subframes = length_samples // subframe_length
  
      # define the subframe shape and the trimmed audio length, removeing any unused
      # excess audio, so subframe fit exactly.
      subframe_shape = outer_dimensions + [
          num_subframes,
          subframe_length,
      ]
      trimmed_input_size = outer_dimensions + [
          num_subframes * subframe_length
      ]
      # slice up the audio into subframes
      subframes = tf.reshape(
          tf.slice(
              signal,
              begin=np.zeros(len(signal_shape), np.int32),
              size=trimmed_input_size,
          ),
          subframe_shape,
      )
  
      # frame_selector is a [num_frames, subframes_per_frame] tensor
      # that indexes into the appropriate frame in subframes. For example:
      # [[0, 0, 0, 0], [2, 2, 2, 2], [4, 4, 4, 4]]
      frame_selector = np.reshape(
          np.arange(num_frames) * subframes_per_hop, [num_frames, 1]
      )
  
      # subframe_selector is a [num_frames, subframes_per_frame] tensor
      # that indexes into the appropriate subframe within a frame. For example:
      # [[0, 1, 2, 3], [0, 1, 2, 3], [0, 1, 2, 3]]
      subframe_selector = np.reshape(
          np.arange(subframes_per_frame), [1, subframes_per_frame]
      )
  
      # Adding the 2 selector tensors together produces a [num_frames,
      # subframes_per_frame] tensor of indices to use with tf.gather to select
      # subframes from subframes. We then reshape the inner-most subframes_per_frame
      # dimension to stitch the subframes together into frames. For example:
      # [[0, 1, 2, 3], [2, 3, 4, 5], [4, 5, 6, 7]].
      selector = frame_selector + subframe_selector
      frames = tf.reshape(
          tf.gather(
              subframes, selector.astype(np.int32), axis=gather_axis
          ),
          output_shape,
      )
  
      return frames
  
file_path: kapre/kapre/tflite_compatible_stft.py
imports: import math
  import tensorflow
  import numpy
label_desc: Use image node_id 3 for calling a global function with example usage: fixed_frame(signal, frame_length, frame_step) and returns: frames