code: def prepare(
      dirha_dir: str,
      fs: int,
      audio_dir: str,
      data_dir: Optional[str],
      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
  
      for m in dirha_dir.glob("**/*.mat"):
          # FIXME(kamo): Using all IRs here regardless of mic type
          if m.stem == "ref-chirp":
              continue
          # (Time, Channel) or (Channel, Time)
          x = scipy.io.loadmat(m)["risp_imp"]
          if x.shape[0] == 1:
              x = x[0]
          elif x.shape[1] == 1:
              x = x[:, 0]
          else:
              raise RuntimeError(m, x.shape)
          # 48khz impulse response
          r = 48000
          if r != fs:
              x = resampy.resample(x, r, fs, axis=0)
          # Rescale
          x = 0.95 * x / max(abs(x))
          owav = audio_dir / m.parent.name / f"{m.stem}.{audio_format}"
          owav.parent.mkdir(parents=True, exist_ok=True)
          soundfile.write(owav, x, fs)
          if fscp is not None:
              rid = f"{m.parent.name}_{m.stem}"
              fscp.write(f"{rid} {owav}\n")
  
file_path: espnet/egs2/dirha_wsj/asr1/local/prepare_dirha_ir.py
imports: import argparse
  from pathlib import Path
  from typing import Optional
  import resampy
  import scipy.io
  import soundfile
label_desc: Use image node_id 1 for calling a global function with example usage: prepare(dirha_dir, fs, audio_dir, data_dir, audio_format) without return types