|
import pandas as pd
|
|
import os
|
|
|
|
|
|
alignment = pd.read_csv("alignments/all_de_en_alligned.csv", index_col=0)
|
|
|
|
|
|
en_folder_map = {}
|
|
for folder in os.listdir("EN"):
|
|
book_id = folder.split('.')[0]
|
|
en_folder_map[book_id] = folder
|
|
|
|
|
|
def get_de_path(row):
|
|
if "67" in row['book']:
|
|
return os.path.join("DE","67.frankenstein_de_1211_librivox_newly_alligned", "sentence_level_audio", row['DE_audio'])
|
|
return os.path.join("DE", row['book'], "sentence_level_audio", row['DE_audio'])
|
|
|
|
|
|
def get_en_path(row):
|
|
book_id = str(row['book_id'])
|
|
if book_id in en_folder_map:
|
|
return os.path.join("EN", en_folder_map[book_id], "sentence_level_audio", row['EN_audio'] + ".wav")
|
|
return None
|
|
|
|
|
|
alignment['DE_audio'] = alignment.apply(get_de_path, axis=1)
|
|
alignment['EN_audio'] = alignment.apply(get_en_path, axis=1)
|
|
|
|
|
|
alignment = alignment.drop('book', axis=1)
|
|
|
|
|
|
alignment = alignment.dropna(subset=['EN_audio'])
|
|
|
|
|
|
alignment.to_csv("alignments/all_de_en_alligned_cleaned.csv", index=False)
|
|
|
|
print(f"Saved cleaned CSV with {len(alignment)} rows")
|
|
print("\nFirst few rows of cleaned CSV:")
|
|
print(alignment.head())
|
|
|
|
|