code: def prepare(
      dirha_dir: str,
      minimum_duration: float,
      fs: int,
      audio_dir: str,
      data_dir: Optional[str],
      num_files_per_dir: int = 10,
      audio_format: str = "flac",
  ):
      dirha_dir = Path(dirha_dir)
      audio_dir = Path(audio_dir)
      if data_dir is not None:
          data_dir = Path(data_dir)
          data_dir.mkdir(parents=True, exist_ok=True)
          fscp = (data_dir / "wav.scp").open("w")
      else:
          fscp = None
  
      joint = None
      num_files = 0
      num_dir = 0
      for w in dirha_dir.glob("**/*.wav"):
          x, r = soundfile.read(w)
  
          # Concatenate noises until
          # it has 20seconds durations at minimum
          if joint is None:
              joint = x
          else:
              joint = np.concatenate([joint, x])
  
          if (joint.shape[0] / float(r)) >= minimum_duration:
              if r != fs:
                  joint = resampy.resample(joint, r, fs, axis=0)
              num_files += 1
              if num_files % num_files_per_dir == 0:
                  num_dir += 1
              owav = (
                  audio_dir
                  / f"dir.{num_dir}"
                  / f"noise_{num_files}.{audio_format}"
              )
              owav.parent.mkdir(parents=True, exist_ok=True)
              soundfile.write(owav, joint, fs)
  
              if fscp is not None:
                  fscp.write(f"noise_{num_files} {owav}\n")
              joint = None
  
      else:
          if (
              joint is not None
              and (joint.shape[0] / float(r)) < minimum_duration
          ):
              if r != fs:
                  joint = resampy.resample(joint, r, fs, axis=0)
              # Read the last saved file
              owav = (
                  audio_dir
                  / f"dir.{num_dir}"
                  / f"noise_{num_files}.{audio_format}"
              )
              x, r = soundfile.read(owav)
              joint = np.concatenate([x, joint])
              soundfile.write(owav, joint, fs)
  
file_path: espnet/egs2/dirha_wsj/asr1/local/prepare_dirha_noise.py
imports: import argparse
  from pathlib import Path
  from typing import Optional
  import numpy
  import resampy
  import soundfile
label_desc: Use image node_id 1 for calling a global function with example usage: prepare(dirha_dir, minimum_duration, fs, audio_dir, data_dir, num_files_per_dir, audio_format) without return types