代码拉取完成,页面将自动刷新
from scipy.io import wavfile
from pesq import pesq
from pystoi.stoi import stoi
from glob import glob
import os, librosa, sys, argparse
import numpy as np
from tqdm import tqdm
parser = argparse.ArgumentParser()
parser.add_argument('-r', "--results_root", help="Path to test results folder", required=True)
args = parser.parse_args()
sr = 16000
all_files = glob("{}/wavs/*.wav".format(args.results_root))
gt_folder = args.results_root + '/gts/{}'
print('Calculating for {} files'.format(len(all_files)))
total_pesq = 0
total_stoi = 0
total_estoi = 0
for filename in tqdm(all_files):
gt_filename = gt_folder.format(os.path.basename(filename))
rate, deg = wavfile.read(filename)
rate, ref = wavfile.read(gt_filename)
if len(ref.shape) > 1: ref = np.mean(ref, axis=1) #raise ValueError('Audio should be a mono band')
if rate != sr:
ref = librosa.resample(ref.astype(np.float32), rate, sr).astype(np.int16)
rate = sr
if len(ref) > len(deg): x = ref[0 : deg.shape[0]]
elif len(deg) > len(ref):
deg = deg[: ref.shape[0]]
x = ref
else: x = ref
total_pesq += pesq(rate, x, deg, 'nb')
total_stoi += stoi(x, deg, rate, extended=False)
total_estoi += stoi(x, deg, rate, extended=True)
print('Mean PESQ: {}'.format(total_pesq / len(all_files)))
print('Mean STOI: {}'.format(total_stoi / len(all_files)))
print('Mean ESTOI: {}'.format(total_estoi / len(all_files)))
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。