code: def main_body():
      """Main body of this file"""
  
      parser = argparse.ArgumentParser()
  
      # Configurations: read noisyspeech_synthesizer.cfg and gather inputs
      parser.add_argument(
          "--cfg",
          default="noisyspeech_synthesizer.cfg",
          help="Read noisyspeech_synthesizer.cfg for all the details",
      )
      parser.add_argument("--cfg_str", type=str, default="noisy_speech")
      args = parser.parse_args()
  
      params = dict()
      params["args"] = args
      cfgpath = os.path.join(os.path.dirname(__file__), args.cfg)
      assert os.path.exists(
          cfgpath
      ), f"No configuration file as [{cfgpath}]"
  
      cfg = CP.ConfigParser()
      cfg._interpolation = CP.ExtendedInterpolation()
      cfg.read(cfgpath)
      params["cfg"] = cfg._sections[args.cfg_str]
      cfg = params["cfg"]
  
      clean_dir = os.path.join(
          os.path.dirname(__file__), "datasets/clean"
      )
  
      if cfg["speech_dir"] != "None":
          clean_dir = cfg["speech_dir"]
      if not os.path.exists(clean_dir):
          assert False, "Clean speech data is required"
  
      noise_dir = os.path.join(
          os.path.dirname(__file__), "datasets/noise"
      )
  
      if cfg["noise_dir"] != "None":
          noise_dir = cfg["noise_dir"]
      if not os.path.exists:
          assert False, "Noise data is required"
  
      params["n_jobs"] = int(cfg["nj"])
      params["fs"] = int(cfg["sampling_rate"])
      params["audioformat"] = cfg["audioformat"]
      params["audio_length"] = float(cfg["audio_length"])
      params["silence_length"] = float(cfg["silence_length"])
      params["total_hours"] = float(cfg["total_hours"])
  
      # clean singing speech
      params["use_singing_data"] = int(cfg["use_singing_data"])
      params["clean_singing"] = str(cfg["clean_singing"])
      params["singing_choice"] = int(cfg["singing_choice"])
  
      # clean emotional speech
      params["use_emotion_data"] = int(cfg["use_emotion_data"])
      params["clean_emotion"] = str(cfg["clean_emotion"])
  
      # clean mandarin speech
      params["use_mandarin_data"] = int(cfg["use_mandarin_data"])
      params["clean_mandarin"] = str(cfg["clean_mandarin"])
  
      # rir
      params["rir_choice"] = int(cfg["rir_choice"])
      params["lower_t60"] = float(cfg["lower_t60"])
      params["upper_t60"] = float(cfg["upper_t60"])
      params["rir_table_csv"] = str(cfg["rir_table_csv"])
      params["clean_speech_t60_csv"] = str(cfg["clean_speech_t60_csv"])
  
      if (
          cfg["fileindex_start"] != "None"
          and cfg["fileindex_end"] != "None"
      ):
          params["num_files"] = int(cfg["fileindex_end"]) - int(
              cfg["fileindex_start"]
          )
          params["fileindex_start"] = int(cfg["fileindex_start"])
          params["fileindex_end"] = int(cfg["fileindex_end"])
      else:
          params["num_files"] = int(
              (params["total_hours"] * 60 * 60) / params["audio_length"]
          )
          params["fileindex_start"] = 0
          params["fileindex_end"] = params["num_files"]
  
      print("Number of files to be synthesized:", params["num_files"])
  
      params["is_test_set"] = utils.str2bool(cfg["is_test_set"])
      params["clean_activity_threshold"] = float(
          cfg["clean_activity_threshold"]
      )
      params["noise_activity_threshold"] = float(
          cfg["noise_activity_threshold"]
      )
      params["snr_lower"] = int(cfg["snr_lower"])
      params["snr_upper"] = int(cfg["snr_upper"])
  
      params["randomize_snr"] = utils.str2bool(cfg["randomize_snr"])
      params["target_level_lower"] = int(cfg["target_level_lower"])
      params["target_level_upper"] = int(cfg["target_level_upper"])
  
      if "snr" in cfg.keys():
          params["snr"] = int(cfg["snr"])
      else:
          params["snr"] = int(
              (params["snr_lower"] + params["snr_upper"]) / 2
          )
  
      params["noisyspeech_dir"] = utils.get_dir(
          cfg, "noisy_destination", "noisy"
      )
      params["clean_proc_dir"] = utils.get_dir(
          cfg, "clean_destination", "clean"
      )
      params["noise_proc_dir"] = utils.get_dir(
          cfg, "noise_destination", "noise"
      )
  
      if "speech_csv" in cfg.keys() and cfg["speech_csv"] != "None":
          cleanfilenames = pd.read_csv(cfg["speech_csv"])
          cleanfilenames = cleanfilenames["filename"]
      else:
          # cleanfilenames = glob.glob(os.path.join(clean_dir, params['audioformat']))
          cleanfilenames = []
          for path in Path(clean_dir).rglob("*.wav"):
              cleanfilenames.append(str(path.resolve()))
  
      shuffle(cleanfilenames)
      #   add singing voice to clean speech
      if params["use_singing_data"] == 1:
          all_singing = []
          for path in Path(params["clean_singing"]).rglob("*.wav"):
              all_singing.append(str(path.resolve()))
  
          if params["singing_choice"] == 1:  # male speakers
              mysinging = [
                  s
                  for s in all_singing
                  if ("male" in s and "female" not in s)
              ]
  
          elif params["singing_choice"] == 2:  # female speakers
              mysinging = [s for s in all_singing if "female" in s]
  
          elif params["singing_choice"] == 3:  # both male and female
              mysinging = all_singing
          else:  # default both male and female
              mysinging = all_singing
  
          shuffle(mysinging)
          if mysinging is not None:
              all_cleanfiles = cleanfilenames + mysinging
      else:
          all_cleanfiles = cleanfilenames
  
      #   add emotion data to clean speech
      if params["use_emotion_data"] == 1:
          all_emotion = []
          for path in Path(params["clean_emotion"]).rglob("*.wav"):
              all_emotion.append(str(path.resolve()))
  
          shuffle(all_emotion)
          if all_emotion is not None:
              all_cleanfiles = all_cleanfiles + all_emotion
      else:
          print("NOT using emotion data for training!")
  
      #   add mandarin data to clean speech
      if params["use_mandarin_data"] == 1:
          all_mandarin = []
          for path in Path(params["clean_mandarin"]).rglob("*.wav"):
              all_mandarin.append(str(path.resolve()))
  
          shuffle(all_mandarin)
          if all_mandarin is not None:
              all_cleanfiles = all_cleanfiles + all_mandarin
      else:
          print("NOT using non-english (Mandarin) data for training!")
  
      params["cleanfilenames"] = all_cleanfiles
      params["num_cleanfiles"] = len(params["cleanfilenames"])
      # If there are .wav files in noise_dir directory, use those
      # If not, that implies that the noise files are organized into
      # subdirectories by type,
      # so get the names of the non-excluded subdirectories
      if "noise_csv" in cfg.keys() and cfg["noise_csv"] != "None":
          noisefilenames = pd.read_csv(cfg["noise_csv"])
          noisefilenames = noisefilenames["filename"]
      else:
          noisefilenames = glob.glob(
              os.path.join(noise_dir, params["audioformat"])
          )
  
      if len(noisefilenames) != 0:
          shuffle(noisefilenames)
          params["noisefilenames"] = noisefilenames
      else:
          noisedirs = glob.glob(os.path.join(noise_dir, "*"))
          if cfg["noise_types_excluded"] != "None":
              dirstoexclude = cfg["noise_types_excluded"].split(",")
              for dirs in dirstoexclude:
                  noisedirs.remove(dirs)
          shuffle(noisedirs)
          params["noisedirs"] = noisedirs
  
      # Call main_gen() to generate audio
      (
          clean_source_files,
          clean_clipped_files,
          clean_low_activity_files,
          noise_source_files,
          noise_clipped_files,
          noise_low_activity_files,
      ) = main_gen(params)
  
      # Create log directory if needed,
      # and write log files of clipped and low activity files
      log_dir = utils.get_dir(cfg, "log_dir", "Logs")
  
      utils.write_log_file(
          log_dir,
          "source_files.csv",
          clean_source_files + noise_source_files,
      )
      utils.write_log_file(
          log_dir,
          "clipped_files.csv",
          clean_clipped_files + noise_clipped_files,
      )
      utils.write_log_file(
          log_dir,
          "low_activity_files.csv",
          clean_low_activity_files + noise_low_activity_files,
      )
  
      # Compute and print stats about percentange of clipped and low activity files
      total_clean = (
          len(clean_source_files)
          + len(clean_clipped_files)
          + len(clean_low_activity_files)
      )
      total_noise = (
          len(noise_source_files)
          + len(noise_clipped_files)
          + len(noise_low_activity_files)
      )
      pct_clean_clipped = round(
          len(clean_clipped_files) / total_clean * 100, 1
      )
      pct_noise_clipped = round(
          len(noise_clipped_files) / total_noise * 100, 1
      )
      pct_clean_low_activity = round(
          len(clean_low_activity_files) / total_clean * 100, 1
      )
      pct_noise_low_activity = round(
          len(noise_low_activity_files) / total_noise * 100, 1
      )
  
      print(
          "Of the "
          + str(total_clean)
          + " clean speech files analyzed, "
          + str(pct_clean_clipped)
          + "% had clipping, and "
          + str(pct_clean_low_activity)
          + "% had low activity "
          + "(below "
          + str(params["clean_activity_threshold"] * 100)
          + "% active percentage)"
      )
      print(
          "Of the "
          + str(total_noise)
          + " noise files analyzed, "
          + str(pct_noise_clipped)
          + "% had clipping, and "
          + str(pct_noise_low_activity)
          + "% had low activity "
          + "(below "
          + str(params["noise_activity_threshold"] * 100)
          + "% active percentage)"
      )
  
file_path: espnet/egs2/dns_icassp22/enh1/local/noisyspeech_synthesizer.py
imports: import argparse
  import configparser
  import glob
  import multiprocessing
  import os
  import sys
  from pathlib import Path
  from random import shuffle
  import librosa
  import numpy
  import pandas
  from audiolib import activitydetector, audioread, audiowrite, is_clipped, segmental_snr_mixer
  from scipy import signal
  import utils
label_desc: Use image node_id 6 for calling a global function with example usage: main_body() without return types