code: def compute_partial_slices(
      n_samples: int,
      partial_utterance_n_frames: int,
      hop_length: int,
      min_pad_coverage: float = 0.75,
      overlap: float = 0.5,
  ):
      """
      Computes where to split an utterance waveform and its corresponding mel spectrogram to obtain
      partial utterances of <partial_utterance_n_frames> each. Both the waveform and the mel
      spectrogram slices are returned, so as to make each partial utterance waveform correspond to
      its spectrogram. This function assumes that the mel spectrogram parameters used are those
      defined in params_data.py.
  
      The returned ranges may be indexing further than the length of the waveform. It is
      recommended that you pad the waveform with zeros up to wave_slices[-1].stop.
  
      :param n_samples: the number of samples in the waveform
      :param partial_utterance_n_frames: the number of mel spectrogram frames in each partial
      utterance
      :param min_pad_coverage: when reaching the last partial utterance, it may or may not have
      enough frames. If at least <min_pad_coverage> of <partial_utterance_n_frames> are present,
      then the last partial utterance will be considered, as if we padded the audio. Otherwise,
      it will be discarded, as if we trimmed the audio. If there aren't enough frames for 1 partial
      utterance, this parameter is ignored so that the function always returns at least 1 slice.
      :param overlap: by how much the partial utterance should overlap. If set to 0, the partial
      utterances are entirely disjoint.
      :return: the waveform slices and mel spectrogram slices as lists of array slices. Index
      respectively the waveform and the mel spectrogram with these slices to obtain the partial
      utterances.
      """
      assert 0 <= overlap < 1
      assert 0 < min_pad_coverage <= 1
  
      # librosa's function to compute num_frames from num_samples
      n_frames = int(np.ceil((n_samples + 1) / hop_length))
      # frame shift between ajacent partials
      frame_step = max(
          1, int(np.round(partial_utterance_n_frames * (1 - overlap)))
      )
  
      # Compute the slices
      wav_slices, mel_slices = [], []
      steps = max(
          1, n_frames - partial_utterance_n_frames + frame_step + 1
      )
      for i in range(0, steps, frame_step):
          mel_range = np.array([i, i + partial_utterance_n_frames])
          wav_range = mel_range * hop_length
          mel_slices.append(slice(*mel_range))
          wav_slices.append(slice(*wav_range))
  
      # Evaluate whether extra padding is warranted or not
      last_wav_range = wav_slices[-1]
      coverage = (n_samples - last_wav_range.start) / (
          last_wav_range.stop - last_wav_range.start
      )
      if coverage < min_pad_coverage and len(mel_slices) > 1:
          mel_slices = mel_slices[:-1]
          wav_slices = wav_slices[:-1]
  
      return wav_slices, mel_slices
  
file_path: PaddleHub/modules/audio/voice_cloning/lstm_tacotron2/audio_processor.py
imports: from pathlib import Path
  from warnings import warn
  import struct
  from scipy.ndimage.morphology import binary_dilation
  import numpy
  import librosa
label_desc: Use image node_id 3 for calling a global function with example usage: compute_partial_slices(n_samples, partial_utterance_n_frames, hop_length, min_pad_coverage, overlap) and returns: wav_slices,  mel_slices