|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import os
|
|
import csv
|
|
|
|
|
|
ACCENT_FOLDER = 'accent'
|
|
AUDIO_FOLDER = 'audio'
|
|
SYN_AUDIO_FOLDER = 'synthesized_audio'
|
|
HTS_LABELS_FOLDER = 'hts_labels'
|
|
PHONEMES_FOLDER = 'phoneme'
|
|
TEXT_FOLDER = 'text'
|
|
|
|
COLLECTIONS = ['news', 'novel', 'SUS']
|
|
|
|
OUTPUT_CSV = 'metadata.csv'
|
|
|
|
def read_text_file(text_path):
|
|
"""Returns a dict: audio_index -> sentence"""
|
|
mapping = {}
|
|
with open(text_path, 'r', encoding='utf-8') as f:
|
|
for line in f:
|
|
if '. ' in line:
|
|
idx, sentence = line.strip().split('. ', 1)
|
|
idx = idx.zfill(3)
|
|
mapping[idx] = sentence.strip()
|
|
return mapping
|
|
|
|
def read_phoneme_file(filepath):
|
|
phonemes = []
|
|
|
|
with open(filepath, 'r', encoding='utf-8') as f:
|
|
for line in f:
|
|
parts = line.strip().split()
|
|
if len(parts) == 3:
|
|
start, end, label = parts
|
|
start_us = int(start)
|
|
end_us = int(end)
|
|
start_sec = start_us / 1e6
|
|
end_sec = end_us / 1e6
|
|
if label != "#":
|
|
phonemes.append((start_sec, end_sec, label))
|
|
return phonemes
|
|
|
|
def main():
|
|
rows = []
|
|
|
|
for collection in COLLECTIONS:
|
|
print(f"Processing collection: {collection}")
|
|
text_map = read_text_file(f"{TEXT_FOLDER}/{collection}.txt")
|
|
|
|
for audio_index, text in text_map.items():
|
|
file_name = f"{collection}_{audio_index}"
|
|
|
|
|
|
phoneme_path = os.path.join(PHONEMES_FOLDER, collection, f"adr_{collection}_{audio_index}.phs")
|
|
accent_path = os.path.join(ACCENT_FOLDER, collection, f"adr_{collection}_{audio_index}")
|
|
hts_label_path = os.path.join(HTS_LABELS_FOLDER, collection, f"adr_{file_name}.lab")
|
|
|
|
accent = ""
|
|
if os.path.exists(accent_path):
|
|
with open(accent_path, 'r', encoding='utf-8') as f:
|
|
accent = f.read().strip()
|
|
|
|
rows.append([
|
|
AUDIO_FOLDER + '/' + collection + '/adr_' + file_name + '.wav',
|
|
text,
|
|
accent,
|
|
phoneme_path,
|
|
hts_label_path
|
|
])
|
|
|
|
|
|
with open(OUTPUT_CSV, 'w', newline='', encoding='utf-8') as f:
|
|
writer = csv.writer(f, quoting=csv.QUOTE_ALL)
|
|
writer.writerow(["file_name", "text", "accent", "phonemes", "hts_label_path"])
|
|
for row in rows:
|
|
writer.writerow(row)
|
|
|
|
print(f"\n✅ metadata.csv written with {len(rows)} entries.")
|
|
|
|
if __name__ == "__main__":
|
|
main() |