Datasets:
| #!/usr/bin/env python3 | |
| import csv | |
| import json | |
| def convert_csv_to_jsonl(csv_file="vietnamese_ipa_dataset.csv", jsonl_file="vietnamese_ipa_dataset.jsonl"): | |
| """Convert CSV dataset to JSONL format""" | |
| records = [] | |
| # Read CSV file | |
| with open(csv_file, "r", encoding="utf-8") as f: | |
| reader = csv.DictReader(f) | |
| for row in reader: | |
| # Create record with proper structure | |
| record = { | |
| "word": row["word"], | |
| "ipa": row["ipa"], | |
| "audio": { | |
| "path": row["audio_file"], | |
| "sampling_rate": 22050 # Standard sampling rate for gTTS | |
| } | |
| } | |
| records.append(record) | |
| # Write JSONL file | |
| with open(jsonl_file, "w", encoding="utf-8") as f: | |
| for record in records: | |
| f.write(json.dumps(record, ensure_ascii=False) + "\n") | |
| print(f"Converted {len(records)} records from CSV to JSONL") | |
| print(f"Output saved to: {jsonl_file}") | |
| # Display first 5 records | |
| print("\nFirst 5 records:") | |
| for i, record in enumerate(records[:5], 1): | |
| print(f"{i}. {record['word']} -> {record['ipa']}") | |
| return records | |
| if __name__ == "__main__": | |
| convert_csv_to_jsonl() |