code: def time_stretch(
      spectrogram: tf.Tensor,
      factor: float = 1.0,
      method: tf.image.ResizeMethod = tf.image.ResizeMethod.BILINEAR,
  ) -> tf.Tensor:
      """
      Time stretch a spectrogram preserving shape in tensorflow. Note that
      this is an approximation in the frequency domain.
  
      Parameters:
          spectrogram (tf.Tensor):
              Input spectrogram to be time stretched as tensor.
          factor (float):
              (Optional) Time stretch factor, must be > 0, default to `1`.
          method (tf.image.ResizeMethod):
              (Optional) Interpolation method, default to `BILINEAR`.
  
      Returns:
          tf.Tensor:
              Time stretched spectrogram as tensor with same shape.
      """
      T = tf.shape(spectrogram)[0]
      T_ts = tf.cast(tf.cast(T, tf.float32) * factor, tf.int32)[0]
      F = tf.shape(spectrogram)[1]
      ts_spec = tf.image.resize_images(
          spectrogram, [T_ts, F], method=method, align_corners=True
      )
      return tf.image.resize_image_with_crop_or_pad(ts_spec, T, F)
  
imports: import tensorflow
  from tensorflow.signal import hann_window, stft
label_desc: Use image node_id 2 for calling a global function with example usage: time_stretch(spectrogram, factor, method) and returns: tf