code: def main():
      """Run SECS calculation."""
      args = get_parser().parse_args()
  
      # logging info
      if args.verbose > 1:
          logging.basicConfig(
              level=logging.DEBUG,
              format="%(asctime)s (%(module)s:%(lineno)d) %(levelname)s: %(message)s",
          )
      elif args.verbose > 0:
          logging.basicConfig(
              level=logging.INFO,
              format="%(asctime)s (%(module)s:%(lineno)d) %(levelname)s: %(message)s",
          )
      else:
          logging.basicConfig(
              level=logging.WARN,
              format="%(asctime)s (%(module)s:%(lineno)d) %(levelname)s: %(message)s",
          )
          logging.warning("Skip DEBUG/INFO messages")
  
      # find files
      if os.path.isdir(args.gen_wavdir_or_wavscp):
          gen_files = sorted(find_files(args.gen_wavdir_or_wavscp))
      else:
          with open(args.gen_wavdir_or_wavscp) as f:
              gen_files = [
                  line.strip().split(None, 1)[1]
                  for line in f.readlines()
              ]
          if gen_files[0].endswith("|"):
              raise ValueError("Not supported wav.scp format.")
      if os.path.isdir(args.gt_wavdir_or_wavscp):
          gt_files = sorted(find_files(args.gt_wavdir_or_wavscp))
      else:
          with open(args.gt_wavdir_or_wavscp) as f:
              gt_files = [
                  line.strip().split(None, 1)[1]
                  for line in f.readlines()
              ]
          if gt_files[0].endswith("|"):
              raise ValueError("Not supported wav.scp format.")
  
      if len(gen_files) == 0:
          raise FileNotFoundError(
              "Not found any generated audio files."
          )
      if len(gen_files) > len(gt_files):
          raise ValueError(
              "#groundtruth files are less than #generated files "
              f"(#gen={len(gen_files)} vs. #gt={len(gt_files)}). "
              "Please check the groundtruth directory."
          )
      logging.info("The number of utterances = %d" % len(gen_files))
  
      if torch.cuda.is_available() and ("cuda" in args.device):
          device = args.device
      else:
          device = "cpu"
  
      xv_extractor = XVExtractor(args, device)
  
      # calculate SECS
      secs_dict = dict()
      for i, gen_path in enumerate(gen_files):
          corresponding_list = list(
              filter(
                  lambda gt_path: _get_basename(gt_path) in gen_path,
                  gt_files,
              )
          )
          assert len(corresponding_list) == 1
          gt_path = corresponding_list[0]
          gt_basename = _get_basename(gt_path)
  
          # load wav file as int16
          gen_x, gen_fs = sf.read(gen_path, dtype="int16")
          gt_x, gt_fs = sf.read(gt_path, dtype="int16")
  
          fs = gen_fs
          if gen_fs != gt_fs:
              gt_x = librosa.resample(
                  gt_x.astype(np.float), gt_fs, gen_fs
              )
  
          # Amp Normalization -1 ~ 1
          gen_amax = np.amax(np.absolute(gen_x))
          gen_x = gen_x.astype(np.float32) / gen_amax
          gt_amax = np.amax(np.absolute(gt_x))
          gt_x = gt_x.astype(np.float32) / gt_amax
          # X-vector embedding
          gen_embeds = xv_extractor(gen_x, fs)
          gt_embeds = xv_extractor(gt_x, fs)
          # Cosine Similarity
          secs = 1 - spatial.distance.cosine(
              gen_embeds[0], gt_embeds[0]
          )
          logging.info(f"{gt_basename} {secs:.4f}")
          secs_dict[gt_basename] = secs
  
      # calculate statistics
      mean_secs = np.mean(np.array([v for v in secs_dict.values()]))
      std_secs = np.std(np.array([v for v in secs_dict.values()]))
      logging.info(f"Average: {mean_secs:.4f} ± {std_secs:.4f}")
  
      # write results
      if args.outdir is None:
          if os.path.isdir(args.gen_wavdir_or_wavscp):
              args.outdir = args.gen_wavdir_or_wavscp
          else:
              args.outdir = os.path.dirname(args.gen_wavdir_or_wavscp)
      os.makedirs(args.outdir, exist_ok=True)
      with open(f"{args.outdir}/utt2secs", "w") as f:
          for utt_id in sorted(secs_dict.keys()):
              secs = secs_dict[utt_id]
              f.write(f"{utt_id} {secs:.4f}\n")
      with open(f"{args.outdir}/secs_avg_result.txt", "w") as f:
          f.write(f"#utterances: {len(gen_files)}\n")
          f.write(f"Average: {mean_secs:.4f} ± {std_secs:.4f}")
  
      logging.info("Successfully finished SECS evaluation.")
  
file_path: espnet/egs2/TEMPLATE/enh_st1/pyscripts/utils/evaluate_secs.py
imports: import argparse
  import fnmatch
  import logging
  import os
  from typing import List
  import librosa
  import numpy
  import soundfile
  import torch
  from scipy import spatial
  from speechbrain.dataio.preprocess import AudioNormalizer
  from speechbrain.pretrained import EncoderClassifier
label_desc: Use image node_id 4 for calling a global function with example usage: main() without return types