import os import csv import json from glob import glob import pandas as pd direction_speech = os.getenv("DIRECTION_SPEECH", "enA") direction_text = os.getenv("DIRECTION_TEXT", "jpn") df = pd.concat([ pd.read_csv(i, quoting=csv.QUOTE_NONE, encoding='utf-8', sep='\t', header=None, on_bad_lines='skip') for i in glob(f'metadata.{direction_speech}-{direction_text}.batch_*') ]) line_no = [int(i.split(" ")[-1]) for i in df[0]] text = df[1].values.tolist() os.makedirs("text_corpus", exist_ok=True) with open(f"text_corpus/text.{direction_speech}-{direction_text}.json", "w") as f: json.dump({l: t for l, t in zip(line_no, text)}, f)