<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def eval_dir( reference_dir, estimates_dir, output_dir=None, mode='v4', win=1.0, hop=1.0, ):
 """Compute bss_eval metrics for two given directories assuming file names are identical for both, reference source and estimates. Parameters reference_dir : str path to reference sources directory. estimates_dir : str path to estimates directory. output_dir : str path to output directory used to save evaluation results. Defaults to `None`, meaning no evaluation files will be saved. mode : str bsseval version number. Defaults to 'v4'. win : int window size in Returns ------- scores : EvalStore scores object that holds the framewise and global evaluation scores. """


    reference = []
    estimates = []

    data = EvalStore(win=win, hop=hop)

    global_rate = None
    reference_glob = os.path.join(reference_dir, '*.wav')
    # Load in each reference file in the supplied dir
    for reference_file in glob.glob(reference_glob):
        ref_audio, rate = sf.read(
            reference_file,
            always_2d=True
        )
        # Make sure fs is the same for all files
        assert (global_rate is None or rate == global_rate)
        global_rate = rate
        reference.append(ref_audio)

    if not reference:
        raise ValueError('`reference_dir` contains no wav files')

    estimated_glob = os.path.join(estimates_dir, '*.wav')
    targets = []
    for estimated_file in glob.glob(estimated_glob):
        targets.append(os.path.basename(estimated_file))
        ref_audio, rate = sf.read(
            estimated_file,
            always_2d=True
        )
        assert (global_rate is None or rate == global_rate)
        global_rate = rate
        estimates.append(ref_audio)

    SDR, ISR, SIR, SAR = evaluate(
        reference,
        estimates,
        win=int(win*global_rate),
        hop=int(hop*global_rate),
        mode=mode
    )
    for i, target in enumerate(targets):
        values = {
            "SDR": SDR[i].tolist(),
            "SIR": SIR[i].tolist(),
            "ISR": ISR[i].tolist(),
            "SAR": SAR[i].tolist()
        }

        data.add_target(
            target_name=target,
            values=values
        )

    return data