Delete create_metadata.py
Browse files- create_metadata.py +0 -99
create_metadata.py
DELETED
|
@@ -1,99 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/env python3
|
| 2 |
-
"""
|
| 3 |
-
Script to consolidate all transcript files into a single metadata.csv
|
| 4 |
-
- Only filename and transcript
|
| 5 |
-
- Converts Latin punctuation to Japanese punctuation
|
| 6 |
-
- Ensures each transcript ends with 。 (Kuten)
|
| 7 |
-
"""
|
| 8 |
-
|
| 9 |
-
import csv
|
| 10 |
-
from pathlib import Path
|
| 11 |
-
|
| 12 |
-
BASE_DIR = Path("/home/phucdb/Documents/uv/cpjd_ver1")
|
| 13 |
-
OUTPUT_FILE = BASE_DIR / "metadata.csv"
|
| 14 |
-
|
| 15 |
-
def convert_punctuation(text: str) -> str:
|
| 16 |
-
"""Convert Latin punctuation to Japanese punctuation."""
|
| 17 |
-
# Replace comma with Tōten (、)
|
| 18 |
-
text = text.replace(",", "、")
|
| 19 |
-
text = text.replace(",", "、") # Full-width comma too
|
| 20 |
-
|
| 21 |
-
# Replace period with Kuten (。)
|
| 22 |
-
text = text.replace(".", "。")
|
| 23 |
-
text = text.replace(".", "。") # Full-width period too
|
| 24 |
-
|
| 25 |
-
return text
|
| 26 |
-
|
| 27 |
-
def ensure_ends_with_kuten(text: str) -> str:
|
| 28 |
-
"""Ensure transcript ends with Japanese period (。)."""
|
| 29 |
-
text = text.rstrip()
|
| 30 |
-
if not text.endswith("。"):
|
| 31 |
-
text += "。"
|
| 32 |
-
return text
|
| 33 |
-
|
| 34 |
-
def main():
|
| 35 |
-
rows = []
|
| 36 |
-
|
| 37 |
-
# Find all dialect folders
|
| 38 |
-
for folder in sorted(BASE_DIR.iterdir()):
|
| 39 |
-
if not folder.is_dir():
|
| 40 |
-
continue
|
| 41 |
-
|
| 42 |
-
# Skip if doesn't start with F_ or M_
|
| 43 |
-
if not (folder.name.startswith("F_") or folder.name.startswith("M_")):
|
| 44 |
-
continue
|
| 45 |
-
|
| 46 |
-
dialect = folder.name # e.g., F_akita, M_osaka
|
| 47 |
-
transcript_file = folder / "transcript_utf8.txt"
|
| 48 |
-
|
| 49 |
-
if not transcript_file.exists():
|
| 50 |
-
print(f"Warning: No transcript found in {folder.name}")
|
| 51 |
-
continue
|
| 52 |
-
|
| 53 |
-
print(f"Processing: {dialect}")
|
| 54 |
-
|
| 55 |
-
# Read transcript file
|
| 56 |
-
with open(transcript_file, "r", encoding="utf-8") as f:
|
| 57 |
-
for line in f:
|
| 58 |
-
line = line.strip()
|
| 59 |
-
if not line:
|
| 60 |
-
continue
|
| 61 |
-
|
| 62 |
-
# Parse format "001: content"
|
| 63 |
-
if ": " in line:
|
| 64 |
-
parts = line.split(": ", 1)
|
| 65 |
-
if len(parts) == 2:
|
| 66 |
-
audio_id = parts[0].strip()
|
| 67 |
-
text = parts[1].strip()
|
| 68 |
-
|
| 69 |
-
# Convert punctuation
|
| 70 |
-
text = convert_punctuation(text)
|
| 71 |
-
|
| 72 |
-
# Ensure ends with 。
|
| 73 |
-
text = ensure_ends_with_kuten(text)
|
| 74 |
-
|
| 75 |
-
# Create audio filename (just the filename, not full path)
|
| 76 |
-
filename = f"{dialect}/wav16k_norm/{audio_id}.wav"
|
| 77 |
-
|
| 78 |
-
rows.append({
|
| 79 |
-
"filename": filename,
|
| 80 |
-
"transcript": text
|
| 81 |
-
})
|
| 82 |
-
|
| 83 |
-
# Write to CSV
|
| 84 |
-
print(f"\nWriting {len(rows)} entries to {OUTPUT_FILE}")
|
| 85 |
-
|
| 86 |
-
with open(OUTPUT_FILE, "w", encoding="utf-8", newline="") as f:
|
| 87 |
-
writer = csv.DictWriter(f, fieldnames=["filename", "transcript"])
|
| 88 |
-
writer.writeheader()
|
| 89 |
-
writer.writerows(rows)
|
| 90 |
-
|
| 91 |
-
print("Done!")
|
| 92 |
-
|
| 93 |
-
# Show sample
|
| 94 |
-
print("\n--- Sample entries ---")
|
| 95 |
-
for row in rows[:5]:
|
| 96 |
-
print(f"{row['filename']}: {row['transcript'][:50]}...")
|
| 97 |
-
|
| 98 |
-
if __name__ == "__main__":
|
| 99 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|