|
import os |
|
import csv |
|
import json |
|
|
|
ref_path = os.getenv("REF_PATH") |
|
assert ref_path is not None |
|
with open(ref_path, 'r') as f: |
|
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['prompt_text'], |
|
'tag': item['category'], |
|
'id': f'{c:03d}' |
|
} |
|
c += 1 |
|
|
|
folders = ['human', 't-large', 'p-preview', 'xunfei', 'doubao', 'openai'] |
|
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', '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) |
|
writer.writerow([file_name, v['id'], v['speaker_name'], folder, v['input_text'], v['tag']]) |
|
writer.writerow([]) |
|
|
|
print(f"CSV OK: {csv_file}") |
|
|