code: def add_chunk(
      wav,
      wav_chunk,
      target,
      sample_rate=16000,
      time_resolution=0.01,
      example_length=5,
      min_len=1.0,
      max_len=2.5,
      min_begin_sample=0,
      min_amp=0.4,
      max_amp=1.0,
      chunk_shift=0,
      speech=False,
  ):
      """Add a new source (noise or speech) to an existing chunk of speech.
      The length of the appended signal is randomly selected within the
      min_len-max_len range. The shift is controlled by the  chunk_shift
      parameter.
  
  
      Arguments
      ---------
      wav : torch.tensor
          The waveform to append.
      wav_chunk : torch.tensor
          The existing waveform where to append the new source.
      sample_rate: int
          The sample rate of the input waveforms.
      time_resolution:
          Time resolution of the targets (in seconds)-
      example_length: float
          Duration (in seconds) of the existing chunk.
      min_len: float
          Minimum duration (in seconds) of the waveform to append.
      max_len: float
          Maximum duration (in seconds) of the waveform to append.
      min_begin_sample: int
          It allows sampling the original waveform with some shift. This might
          be useful to avoid the initial sampled of the waveform that can be
          silence samples.
      min_amp: float
          The new waveform is appended with a random amplitude sampled in the
          range min_amp-max_amp.
      max_amp: float
          See min_amp.
      chunk_shift: int
          This parameter controls where to append the new source within the
          existing one.
      speech: bool
          If True, the new waveform is assumed to be a speech signal. The targets
          will be put to 1 for all the duration on the speech signal.
  
      Returns
      -------
      wav_chunk: torch.tensor
          The new waveform with the added signal.
      target: torch.tensor
          The new targets corresponding to the output signal.
      lengths: torch.tensor
          relative lenghts of each chunk.
      end_chunk: int
          The last sample of the appended sequence. It can be used later to add
          another source that do not overlap with the current one.
      """
  
      # Convert from seconds to samples
      min_len_samples = int(sample_rate * min_len)
      max_len_samples = int(sample_rate * max_len)
      last_sample = int(example_length * sample_rate)
  
      # Randomly sampling the length of the chunk to append
      len_chunk = torch.randint(
          low=min_len_samples, high=max_len_samples, size=(1,)
      ).item()
  
      # Randomly sampling the start sample
      max_end_sample = min_begin_sample + (last_sample - len_chunk)
      begin_sample = torch.randint(
          low=min_begin_sample, high=max_end_sample, size=(1,)
      ).item()
      end_chunk = min(chunk_shift + len_chunk, last_sample)
  
      # Randomly sampling the amplitude of the chunk to append
      rand_amp = (
          torch.rand(wav.shape[0], 1, wav.shape[-1], device=wav.device)
          * (max_amp - min_amp)
          + min_amp
      )
  
      # Fetch the signal to append
      wav_to_paste = wav[
          :, begin_sample : begin_sample + (end_chunk - chunk_shift)
      ]
  
      # Random amplitude
      max_v, p = wav_to_paste.abs().max(1)
      wav_to_paste = wav_to_paste.transpose(1, 0) / max_v.unsqueeze(0)
      wav_to_paste = wav_to_paste.transpose(1, 0)
      wav_to_paste = rand_amp * wav_to_paste
  
      # Apply fade_in/fade_out if needed
      if chunk_shift > 0:
          wav_to_paste = fade_in(wav_to_paste.transpose(1, -1))
          wav_to_paste = wav_to_paste.transpose(1, -1)
  
      if end_chunk < last_sample:
          wav_to_paste = fade_out(wav_to_paste.transpose(1, -1))
          wav_to_paste = wav_to_paste.transpose(1, -1)
  
      # Append the signal
      wav_chunk[:, chunk_shift:end_chunk] = (
          wav_chunk[:, chunk_shift:end_chunk] + wav_to_paste
      )
  
      # Update targets if the appended signal is speech.
      if speech:
          beg_speech_target = int(
              chunk_shift / (sample_rate * time_resolution)
          )
          end_speech_target = int(
              end_chunk / (sample_rate * time_resolution)
          )
          target[:, beg_speech_target:end_speech_target] = 1
  
      # Lenth computation
      lenghts = torch.ones(
          wav_chunk.shape[0], wav_chunk.shape[-1], device=wav.device
      )
      return wav_chunk, target, lenghts, end_chunk
  
file_path: speechbrain/recipes/LibriParty/VAD/data_augment.py
imports: import torch
  import torchaudio
  import random
label_desc: Use image node_id 1 for calling a global function with example usage: add_chunk(wav, wav_chunk, target, sample_rate, time_resolution, example_length, min_len, max_len, min_begin_sample, min_amp, max_amp, chunk_shift, speech) and returns: wav_chunk,  target,  lenghts,  end_chunk