code: def main():
      args = get_args()
  
      feature_config_path = args.feature_config_path
      manifest_paths = args.manifest_path
      audio_dirs = args.audio_dir
      feature_dirs = args.feature_dir
      feature_name_str = args.feature_names
      mask_field = args.mask_field
      stats_path = args.stats_path
      overwrite = args.overwrite
  
      if not (
          len(manifest_paths) == len(audio_dirs) == len(feature_dirs)
      ):
          raise ValueError(
              f"Need same number of manifest, audio_dir, and feature_dir. Received: "
              f"{len(manifest_paths)}, "
              f"{len(audio_dirs)}, "
              f"{len(feature_dirs)}"
          )
  
      for manifest_path, audio_dir, feature_dir in zip(
          manifest_paths, audio_dirs, feature_dirs
      ):
          if not manifest_path.exists():
              raise ValueError(
                  f"Manifest {manifest_path} does not exist."
              )
  
          if not audio_dir.exists():
              raise ValueError(
                  f"Audio directory {audio_dir} does not exist."
              )
  
          if not feature_dir.exists():
              raise ValueError(
                  f"Feature directory {feature_dir} does not exist. "
                  f"Please check that the path is correct and that you ran compute_features.py"
              )
  
      if stats_path.exists():
          if overwrite:
              print(f"Will overwrite existing stats path: {stats_path}")
          else:
              raise ValueError(
                  f"Stats path already exists: {stats_path}"
              )
  
      feature_config = OmegaConf.load(feature_config_path)
      feature_config = instantiate(feature_config)
      featurizer_dict = feature_config.featurizers
  
      print(f"Found featurizers for {list(featurizer_dict.keys())}.")
      featurizers = featurizer_dict.values()
  
      feature_names = feature_name_str.split(",")
      # For each feature, we have a dictionary mapping speaker IDs to a list containing all features
      # for that speaker
      feature_stats = {
          name: defaultdict(list) for name in feature_names
      }
  
      for manifest_path, audio_dir, feature_dir in zip(
          manifest_paths, audio_dirs, feature_dirs
      ):
          entries = read_manifest(manifest_path)
  
          for entry in tqdm(entries):
              speaker = entry["speaker"]
  
              entry_dict = {}
              for featurizer in featurizers:
                  feature_dict = featurizer.load(
                      manifest_entry=entry,
                      audio_dir=audio_dir,
                      feature_dir=feature_dir,
                  )
                  entry_dict.update(feature_dict)
  
              if mask_field:
                  mask = entry_dict[mask_field]
              else:
                  mask = None
  
              for feature_name in feature_names:
                  values = entry_dict[feature_name]
                  if mask is not None:
                      values = values[mask]
  
                  feature_stat_dict = feature_stats[feature_name]
                  feature_stat_dict["default"].append(values)
                  feature_stat_dict[speaker].append(values)
  
      stat_dict = defaultdict(dict)
      for feature_name in feature_names:
          mean_key = f"{feature_name}_mean"
          std_key = f"{feature_name}_std"
          feature_stat_dict = feature_stats[feature_name]
          for speaker_id, values in feature_stat_dict.items():
              speaker_mean, speaker_std = _compute_stats(values)
              stat_dict[speaker_id][mean_key] = speaker_mean
              stat_dict[speaker_id][std_key] = speaker_std
  
      with open(stats_path, "w", encoding="utf-8") as stats_f:
          json.dump(stat_dict, stats_f, indent=4)
  
file_path: NeMo/scripts/dataset_processing/tts/compute_feature_stats.py
imports: import argparse
  import json
  from collections import defaultdict
  from pathlib import Path
  from typing import List, Tuple
  import torch
  from hydra.utils import instantiate
  from omegaconf import OmegaConf
  from tqdm import tqdm
  from nemo.collections.asr.parts.utils.manifest_utils import read_manifest
label_desc: Use image node_id 3 for calling a global function with example usage: main() without return types