code: def eval_PESQ(
      ref,
      enh,
      fs,
      compute_permutation: bool = True,
      wideband: bool = True,
  ):
      """Evaluate PESQ
  
      PESQ program can be downloaded from here:
          http://www.itu.int/rec/dologin_pub.asp?lang=e&id=T-REC-P.862-200511-I!Amd2!SOFT-ZST-E&type=items
  
      Reference:
          Perceptual evaluation of speech quality (PESQ)-a new method
              for speech quality assessment of telephone networks and codecs
          https://ieeexplore.ieee.org/document/941023
  
      :param x (np.ndarray): Reference (Nsrc, Nframe, Nmic)
      :param y (np.ndarray): Enhanced (Nsrc, Nframe, Nmic)
      :param fs (int): Sample frequency
      :param compute_permutation (bool):
      """
      if shutil.which("PESQ") is None:
          raise RuntimeError("PESQ: command not found: Please install")
      if fs not in (8000, 16000):
          raise ValueError(
              "Sample frequency must be 8000 or 16000: {}".format(fs)
          )
      if ref.shape != enh.shape:
          raise ValueError(
              "ref and enh should have the same shape: {} != {}".format(
                  ref.shape, enh.shape
              )
          )
      if ref.ndim != 3:
          raise ValueError(
              "Input must have 3 dims: {}".format_map(ref.ndim)
          )
  
      n_src = ref.shape[0]
      n_mic = ref.shape[2]
      with TemporaryDirectory() as d:
          # Dumping wav files temporary
          ref_files = []
          enh_files = []
          for isrc in range(n_src):
              refs = []  # [Nsrc, Nmic]
              enhs = []  # [Nsrc, Nmic]
              for imic in range(n_mic):
                  wv = str(
                      os.path.join(
                          d, "ref.{}.{}.wav".format(isrc, imic)
                      )
                  )
                  soundfile.write(
                      wv, ref[isrc, :, imic].astype(np.int16), fs
                  )
                  refs.append(wv)
  
                  wv = str(
                      os.path.join(
                          d, "enh.{}.{}.wav".format(isrc, imic)
                      )
                  )
                  soundfile.write(
                      wv, enh[isrc, :, imic].astype(np.int16), fs
                  )
                  enhs.append(wv)
              ref_files.append(refs)
              enh_files.append(enhs)
  
          if compute_permutation:
              index_list = list(itertools.permutations(range(n_src)))
          else:
              index_list = [list(range(n_src))]
  
          values = []
          for indices in index_list:
              values2 = []
              for i, j in enumerate(indices):
                  lis = []
                  for imic in range(n_mic):
                      # PESQ +<8000|16000> <ref.wav> <enh.wav> [smos] [cond]
                      if wideband:
                          commands = [
                              "PESQ",
                              "+{}".format(fs),
                              "+wb",
                              ref_files[i][imic],
                              enh_files[j][imic],
                          ]
                      else:
                          commands = [
                              "PESQ",
                              "+{}".format(fs),
                              ref_files[i][imic],
                              enh_files[j][imic],
                          ]
                      with subprocess.Popen(
                          commands, stdout=subprocess.DEVNULL, cwd=d
                      ) as p:
                          _, _ = p.communicate()
  
                      # e.g.
                      # REFERENCE	 DEGRADED	 PESQMOS	 MOSLQO	 SAMPLE_FREQ	 MODE
                      # /tmp/t/ref.0.wav	 /tmp/t/enh.0.wav	 -1.000	 4.644	 16000	wb
                      result_txt = Path(d) / "pesq_results.txt"
                      if result_txt.exists():
                          with result_txt.open("r") as f:
                              lis.append(
                                  float(f.readlines()[1].split()[3])
                              )
                      else:
                          # Sometimes PESQ is failed. I don't know why.
                          warnings.warn("Processing error is found.")
                          lis.append(1.0)
                      # Averaging over n_mic
                  # Averaging over n_mic
                  values2.append(sum(lis) / len(lis))
              values.append(values2)
      best_pairs = sorted(
          [(v, i) for v, i in zip(values, index_list)],
          key=lambda x: sum(x[0]),
      )[-1]
      value, perm = best_pairs
      return tuple(value), tuple(perm)
  
imports: import argparse
  import itertools
  import logging
  import os
  import shutil
  import subprocess
  import sys
  import warnings
  from collections import OrderedDict
  from distutils.util import strtobool
  from pathlib import Path
  from tempfile import TemporaryDirectory
  import museval
  import numpy
  import soundfile
  from pystoi.stoi import stoi
  from espnet.utils.cli_utils import get_commandline_args
label_desc: Use image node_id 2 for calling a global function with example usage: eval_PESQ(ref, enh, fs, compute_permutation, wideband) and returns: tuple,  tuple