code: def reorder_refs_or_hyps(
      result_dir, num_spkrs, all_keys, hyp_or_ref=None, perms=None
  ):
      assert hyp_or_ref in ["hyp", "ref"]
      if hyp_or_ref == "ref":
          assert perms is None
          perms = [np.arange(0, num_spkrs) for _ in all_keys]
  
      orig_trns = []
      for i in range(1, num_spkrs + 1):
          orig_trns.append(
              read_trn(Path(result_dir, f"{hyp_or_ref}_spk{i}.trn"))
          )
          if i > 1:
              assert list(orig_trns[0].keys()) == list(
                  orig_trns[-1].keys()
              )
  
      with open(
          Path(result_dir, f"{hyp_or_ref}.trn"), "w", encoding="utf-8"
      ) as f:
          for idx, (key, perm) in enumerate(
              zip(orig_trns[0].keys(), perms)
          ):
              # todo: clean this part, because sclite turn all ids in to lower characters.
              assert key.lower() == all_keys[idx].lower()
              for i in range(num_spkrs):
                  f.write(
                      orig_trns[perm[i]][key]
                      + f"\t({key}-{i+1})"
                      + "\n"
                  )
  
file_path: espnet/egs2/voices/asr1/pyscripts/utils/eval_perm_free_error.py
imports: import argparse
  import codecs
  import re
  import sys
  from collections import OrderedDict
  from pathlib import Path
  from typing import List
  import numpy
  from scipy.optimize import linear_sum_assignment
label_desc: Use image node_id 7 for calling a global function with example usage: reorder_refs_or_hyps(result_dir, num_spkrs, all_keys, hyp_or_ref, perms) without return types