File size: 1,569 Bytes
160f9ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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}")