(signal, frame_length, frame_step, first_axis=False)
return frames
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.
    first_axis: If true, framing is applied to first axis of tensor; otherwise,
      it is applied to last axis.

  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.
tflite-compatible tf.signal.frame for fixed-size input.
tflite - compatible tf . signal . frame for fixed - size input .
def _fixed_frame(signal, frame_length, frame_step, first_axis=False):
  """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.
    first_axis: If true, framing is applied to first axis of tensor; otherwise,
      it is applied to last axis.

  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 = signal.shape.as_list()
  if first_axis:
    length_samples = signal_shape[0]
  else:
    length_samples = signal_shape[-1]
  if length_samples <= 0:
    raise ValueError('fixed framing requires predefined constant signal length')
  num_frames = max(0, 1 + (length_samples - frame_length) // frame_step)
  if first_axis:
    inner_dimensions = signal_shape[1:]
    result_shape = [num_frames, frame_length] + inner_dimensions
    gather_axis = 0
  else:
    outer_dimensions = signal_shape[:-1]
    result_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 = fractions.gcd(frame_length, frame_step)  # pylint: disable=deprecated-method
  subframes_per_frame = frame_length // subframe_length
  subframes_per_hop = frame_step // subframe_length
  num_subframes = length_samples // subframe_length

  if first_axis:
    trimmed_input_size = [num_subframes * subframe_length] + inner_dimensions
    subframe_shape = [num_subframes, subframe_length] + inner_dimensions
  else:
    trimmed_input_size = outer_dimensions + [num_subframes * subframe_length]
    subframe_shape = outer_dimensions + [num_subframes, subframe_length]
  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),
      result_shape)
  return frames
def _fixed_frame ( signal , frame_length , frame_step , first_axis = False ) : signal_shape = signal . shape . as_list ( ) if first_axis : length_samples = signal_shape [ 0 ] else : length_samples = signal_shape [ - 1 ] if length_samples <= 0 : raise ValueError ( 'fixed framing requires predefined constant signal length' ) num_frames = max ( 0 , 1 + ( length_samples - frame_length ) // frame_step ) if first_axis : inner_dimensions = signal_shape [ 1 : ] result_shape = [ num_frames , frame_length ] + inner_dimensions gather_axis = 0 else : outer_dimensions = signal_shape [ : - 1 ] result_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 = fractions . gcd ( frame_length , frame_step ) # pylint: disable=deprecated-method subframes_per_frame = frame_length // subframe_length subframes_per_hop = frame_step // subframe_length num_subframes = length_samples // subframe_length if first_axis : trimmed_input_size = [ num_subframes * subframe_length ] + inner_dimensions subframe_shape = [ num_subframes , subframe_length ] + inner_dimensions else : trimmed_input_size = outer_dimensions + [ num_subframes * subframe_length ] subframe_shape = outer_dimensions + [ num_subframes , subframe_length ] 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 ) , result_shape ) return frames