code: def activitydetector(
      audio, fs=16000, energy_thresh=0.13, target_level=-25
  ):
      """Return the percentage of the time the audio signal is above an energy threshold"""
  
      audio = normalize(audio, target_level)
      window_size = 50  # in ms
      window_samples = int(fs * window_size / 1000)
      sample_start = 0
      cnt = 0
      prev_energy_prob = 0
      active_frames = 0
  
      a = -1
      b = 0.2
      alpha_rel = 0.05
      alpha_att = 0.8
  
      while sample_start < len(audio):
          sample_end = min(sample_start + window_samples, len(audio))
          audio_win = audio[sample_start:sample_end]
          frame_rms = 20 * np.log10(sum(audio_win**2) + EPS)
          frame_energy_prob = 1.0 / (1 + np.exp(-(a + b * frame_rms)))
  
          if frame_energy_prob > prev_energy_prob:
              smoothed_energy_prob = (
                  frame_energy_prob * alpha_att
                  + prev_energy_prob * (1 - alpha_att)
              )
          else:
              smoothed_energy_prob = (
                  frame_energy_prob * alpha_rel
                  + prev_energy_prob * (1 - alpha_rel)
              )
  
          if smoothed_energy_prob > energy_thresh:
              active_frames += 1
          prev_energy_prob = frame_energy_prob
          sample_start += window_samples
          cnt += 1
  
      perc_active = active_frames / cnt
      return perc_active
  
file_path: speechbrain/recipes/DNS/noisyspeech_synthesizer/audiolib.py
imports: import os
  import numpy
  import soundfile
  import subprocess
  import glob
  import librosa
label_desc: Use image node_id 12 for calling a global function with example usage: activitydetector(audio, fs, energy_thresh, target_level) and returns: perc_active