|
|
|
|
|
import csv |
|
|
|
file = open('speakers_all.csv', newline='') |
|
outfile = open('metadata.csv', 'w', newline='') |
|
writer = csv.DictWriter(outfile, ["file_name", "label", "birthplace", "country", "native_language", "sex", "age", "age_onset"]) |
|
detail_countries = {"usa","uk","canada","australia"} |
|
def processrow(row): |
|
filename = "recordings/" + row["filename"] + ".mp3" |
|
label = row["country"] |
|
if row["country"] in detail_countries: |
|
label = ", ".join(row["birthplace"].split(", ")[-2:]) |
|
if label == "va, usa": |
|
label = "virginia, usa" |
|
birthplace = row["birthplace"] |
|
age = row["age"] |
|
age_onset = row["age_onset"] |
|
sex = row["sex"] |
|
country = row["country"] |
|
language = row["native_language"] |
|
if row["file_missing?"] != "TRUE" and language != "synthesized": |
|
writer.writerow({"file_name": filename, "label": label, "birthplace": birthplace, "country": country, "native_language": language, "sex": sex, "age": age, "age_onset": age_onset}) |
|
|
|
writer.writeheader() |
|
for row in csv.DictReader(file): |
|
processrow(row) |
|
|
|
outfile.close() |
|
file.close() |
|
|