code: def process_dataset(
      args,
      n_shards: int,
      node_index: int,
      task_index: tp.Optional[int] = None,
  ):
      if task_index is None:
          env = submitit.JobEnvironment()
          task_index = env.global_rank
      shard_index = node_index * args.tasks_per_node + task_index
  
      if args.files_path is None:
          lines = [
              m.path
              for m in find_audio_files(
                  args.root_path,
                  resolve=False,
                  progress=True,
                  workers=8,
              )
          ]
      else:
          files_path = Path(args.files_path)
          if files_path.suffix == ".txt":
              print(
                  f"Reading file list from .txt file: {args.files_path}"
              )
              lines = read_txt_files(args.files_path)
          else:
              print(f"Reading file list from egs: {args.files_path}")
              lines = read_egs_files(args.files_path)
  
      total_files = len(lines)
      print(
          f"Total of {total_files} processed with {n_shards} shards. "
          + f"Current idx = {shard_index} -> {total_files // n_shards} files to process"
      )
      for idx, line in tqdm.tqdm(enumerate(lines)):
          # skip if not part of this shard
          if idx % n_shards != shard_index:
              continue
  
          path = str(AudioCraftEnvironment.apply_dataset_mappers(line))
          root_path = str(args.root_path)
          if not root_path.endswith("/"):
              root_path += "/"
          assert path.startswith(
              str(root_path)
          ), f"Mismatch between path and provided root: {path} VS {root_path}"
  
          try:
              metadata_path = Path(path).with_suffix(".json")
              out_path = args.out_path / path[len(root_path) :]
              out_metadata_path = out_path.with_suffix(".json")
              out_done_token = out_path.with_suffix(".done")
  
              # don't reprocess existing files
              if out_done_token.exists():
                  continue
  
              print(idx, out_path, path)
              mix, sr = audio_read(path)
              mix_channels = (
                  args.channels
                  if args.channels is not None and args.channels > 0
                  else mix.size(0)
              )
              # enforce simple stereo
              out_channels = mix_channels
              if out_channels > 2:
                  print(
                      f"Mix has more than two channels: {out_channels}, enforcing 2 channels"
                  )
                  out_channels = 2
              out_sr = (
                  args.sample_rate
                  if args.sample_rate is not None
                  else sr
              )
              out_wav = convert_audio(mix, sr, out_sr, out_channels)
              audio_write(
                  out_path.with_suffix(""),
                  out_wav,
                  sample_rate=out_sr,
                  format=args.format,
                  normalize=False,
                  strategy="clip",
              )
              if metadata_path.exists():
                  shutil.copy(metadata_path, out_metadata_path)
              else:
                  print(f"No metadata found at {str(metadata_path)}")
              out_done_token.touch()
          except Exception as e:
              print(f"Error processing file line: {line}, {e}")
  
file_path: audiocraft/scripts/resample_dataset.py
imports: import argparse
  from pathlib import Path
  import shutil
  import typing
  import submitit
  import tqdm
  from audiocraft.data.audio import audio_read, audio_write
  from audiocraft.data.audio_dataset import load_audio_meta, find_audio_files
  from audiocraft.data.audio_utils import convert_audio
  from audiocraft.environment import AudioCraftEnvironment
label_desc: Use image node_id 3 for calling a global function with example usage: process_dataset(args, n_shards, node_index, task_index) without return types