import os import csv import json ref_path = os.getenv("REF_PATH") cer_path = os.getenv("CER_PATH") sim_path = os.getenv("SIM_PATH") assert ref_path is not None with open(ref_path, 'r') as f: data = json.load(f) with open(cer_path, 'r') as f: cer_data = json.load(f) with open(sim_path, 'r') as f: sim_data = json.load(f) ref = {} c = 1 for item in data: k = item['ref_wav_path'] ref[k] = { 'speaker_name': item['up_name'], 'input_text': item['text'], 'tag': item['category'], 'id': f'{c:03d}' } c += 1 folders = ['human', 't-large', 'p-preview', 'xunfei', 'doubao'] csv_file = 'metadata.csv' with open(csv_file, mode='w', newline='') as file: writer = csv.writer(file) writer.writerow(['file_name', 'id', 'speaker_name', 'TTS_method', 'input_text', 'cer', 'sim', 'tag']) for item in os.listdir('human'): v = ref[item] for folder in folders: file_id = item.split('.')[0] if folder in ['xunfei', 'doubao']: file_name = os.path.join(folder, file_id + '.mp3') else: file_name = os.path.join(folder, item) if folder in ['human']: writer.writerow([file_name, v['id'], v['speaker_name'], folder, v['input_text'], 0., 1., v['tag']]) else: writer.writerow([file_name, v['id'], v['speaker_name'], folder, v['input_text'], cer_data[file_id][folder+'_cer'], sim_data[file_id][folder+'_sim'], v['tag']]) writer.writerow([]) print(f"CSV OK: {csv_file}")