class_docstr: A ready-to-use class for Voice Activity Detection (VAD) using a
  pre-trained model.
  
  Example
  -------
  >>> import torchaudio
  >>> from speechbrain.inference.VAD import VAD
  >>> # Model is downloaded from the speechbrain HuggingFace repo
  >>> tmpdir = getfixture("tmpdir")
  >>> VAD = VAD.from_hparams(
  ...     source="speechbrain/vad-crdnn-libriparty",
  ...     savedir=tmpdir,
  ... )
  
  >>> # Perform VAD
  >>> boundaries = VAD.get_speech_segments("tests/samples/single-mic/example1.wav")
docstr: Applies energy-based VAD within the detected speech segments.The neural
  network VAD often creates longer segments and tends to merge segments that
  are close with each other.
  
  The energy VAD post-processes can be useful for having a fine-grained voice
  activity detection.
  
  The energy VAD computes the energy within the small chunks. The energy is
  normalized within the segment to have mean 0.5 and +-0.5 of std.
  This helps to set the energy threshold.
  
  Arguments
  ---------
  audio_file: path
      Path of the audio file containing the recording. The file is read
      with torchaudio.
  boundaries : torch.Tensor
      Tensor containing the speech boundaries. It can be derived using the
      get_boundaries method.
  activation_th: float
      A new speech segment is started it the energy is above activation_th.
  deactivation_th: float
      The segment is considered ended when the energy is <= deactivation_th.
  eps: float
      Small constant for numerical stability.
  
  
  Returns
  -------
  new_boundaries
      The new boundaries that are post-processed by the energy VAD.
docstr_tok: ["Applies","energy-based","VAD","within","the","detected","speech","segments.The","neural","network","VAD","often","creates","longer","segments","and","tends","to","merge","segments","that","are","close","with","each","other",".","The","energy","VAD","post-processes","can","be","useful","for","having","a","fine-grained","voice","activity","detection",".","The","energy","VAD","computes","the","energy","within","the","small","chunks",".","The","energy","is","normalized","within","the","segment","to","have","mean","0.5","and","+-0.5","of","std",".","This","helps","to","set","the","energy","threshold",".","Arguments","--","--","--","--","-","audio_file",":","path","Path","of","the","audio","file","containing","the","recording",".","The","file","is","read","with","torchaudio",".","boundaries",":","torch.Tensor","Tensor","containing","the","speech","boundaries",".","It","can","be","derived","using","the","get_boundaries","method",".","activation_th",":","float","A","new","speech","segment","is","started","it","the","energy","is","above","activation_th",".","deactivation_th",":","float","The","segment","is","considered","ended","when","the","energy","is","<","=","deactivation_th",".","eps",":","float","Small","constant","for","numerical","stability",".","Returns","--","--","--","-","new_boundaries","The","new","boundaries","that","are","post-processed","by","the","energy","VAD","."]
code: def energy_VAD(
      self,
      audio_file,
      boundaries,
      activation_th=0.5,
      deactivation_th=0.0,
      eps=1e-6,
  ):
      """Applies energy-based VAD within the detected speech segments.The neural
      network VAD often creates longer segments and tends to merge segments that
      are close with each other.
  
      The energy VAD post-processes can be useful for having a fine-grained voice
      activity detection.
  
      The energy VAD computes the energy within the small chunks. The energy is
      normalized within the segment to have mean 0.5 and +-0.5 of std.
      This helps to set the energy threshold.
  
      Arguments
      ---------
      audio_file: path
          Path of the audio file containing the recording. The file is read
          with torchaudio.
      boundaries : torch.Tensor
          Tensor containing the speech boundaries. It can be derived using the
          get_boundaries method.
      activation_th: float
          A new speech segment is started it the energy is above activation_th.
      deactivation_th: float
          The segment is considered ended when the energy is <= deactivation_th.
      eps: float
          Small constant for numerical stability.
  
  
      Returns
      -------
      new_boundaries
          The new boundaries that are post-processed by the energy VAD.
      """
  
      # Getting the total size of the input file
      sample_rate, audio_len = self._get_audio_info(audio_file)
  
      if sample_rate != self.sample_rate:
          raise ValueError(
              "The detected sample rate is different from that set in the hparam file"
          )
  
      # Computing the chunk length of the energy window
      chunk_len = int(self.time_resolution * sample_rate)
      new_boundaries = []
  
      # Processing speech segments
      for i in range(boundaries.shape[0]):
          begin_sample = int(boundaries[i, 0] * sample_rate)
          end_sample = int(boundaries[i, 1] * sample_rate)
          seg_len = end_sample - begin_sample
  
          # Reading the speech segment
          segment, _ = torchaudio.load(
              audio_file, frame_offset=begin_sample, num_frames=seg_len
          )
  
          # Create chunks
          segment_chunks = self.create_chunks(
              segment, chunk_size=chunk_len, chunk_stride=chunk_len
          )
  
          # Energy computation within each chunk
          energy_chunks = segment_chunks.abs().sum(-1) + eps
          energy_chunks = energy_chunks.log()
  
          # Energy normalization
          energy_chunks = (
              (energy_chunks - energy_chunks.mean())
              / (2 * energy_chunks.std())
          ) + 0.5
          energy_chunks = energy_chunks.unsqueeze(0).unsqueeze(2)
  
          # Apply threshold based on the energy value
          energy_vad = self.apply_threshold(
              energy_chunks,
              activation_th=activation_th,
              deactivation_th=deactivation_th,
          )
  
          # Get the boundaries
          energy_boundaries = self.get_boundaries(
              energy_vad, output_value="seconds"
          )
  
          # Get the final boundaries in the original signal
          for j in range(energy_boundaries.shape[0]):
              start_en = boundaries[i, 0] + energy_boundaries[j, 0]
              end_end = boundaries[i, 0] + energy_boundaries[j, 1]
              new_boundaries.append([start_en, end_end])
  
      # Convert boundaries to tensor
      new_boundaries = torch.FloatTensor(new_boundaries).to(
          boundaries.device
      )
      return new_boundaries
  
imports: import torch
  import torchaudio
  from speechbrain.utils.data_utils import split_path
  from speechbrain.utils.fetching import fetch
  from speechbrain.inference.interfaces import Pretrained
label_desc: Use image node_id 10 for calling the VAD obj's underlying member method code with example usage: obj.energy_VAD(audio_file, boundaries, activation_th, deactivation_th, eps) and returns: new_boundaries