LibriReplay-DOA / build_test_csv.py
anonymous
anonymous LibriReplay-DOA test set upload
35d0686
import os
import csv
import re
REC_ROOT = "audio/recorded"
CLEAN_ROOT = "audio/clean"
ASR_DIR = "annotations/asr_label"
VAD_DIR = "annotations/speaker_activity"
rows = []
for location in sorted(os.listdir(REC_ROOT)):
loc_dir = os.path.join(REC_ROOT, location)
if not os.path.isdir(loc_dir):
continue
for wav in sorted(os.listdir(loc_dir)):
if not wav.endswith(".wav"):
continue
# 例:
# doa_0-240-120_session-001_ovlp_75-100_spk0-3570_spk1-1188_spk2-8463.wav
# 提取 session_key
m = re.match(r"^(doa_[^_]+)_(session-.*)\.wav$", wav)
if not m:
continue
session_key = m.group(2)
recorded_path = f"{REC_ROOT}/{location}/{wav}"
# 找该 session 的所有 speaker clean 文件
for spk_id in ["spk0", "spk1", "spk2"]:
clean_filename = f"{session_key}_{spk_id}_clean.wav"
clean_path = f"{CLEAN_ROOT}/{clean_filename}"
if not os.path.exists(clean_path):
continue
asr_filename = f"{session_key}_{spk_id}_label.txt"
asr_path = f"{ASR_DIR}/{asr_filename}"
vad_filename = f"{session_key}_{spk_id}_clean.txt"
vad_path = f"{VAD_DIR}/{vad_filename}"
if not os.path.exists(asr_path):
continue
sample_id = f"{location}_{session_key}_{spk_id}"
rows.append([
sample_id,
location,
session_key,
spk_id,
recorded_path,
clean_path,
asr_path,
vad_path
])
with open("test.csv", "w", newline="") as f:
writer = csv.writer(f)
writer.writerow([
"id",
"location",
"session_key",
"speaker_id",
"recorded_path",
"clean_path",
"asr_label_path",
"speaker_activity_path"
])
writer.writerows(rows)
print("Generated test.csv with", len(rows), "rows")