| |
|
|
| from datasets import Dataset |
| import json |
|
|
|
|
| def test_local_dataset(): |
| """Test loading the dataset locally with Hugging Face datasets""" |
|
|
| |
| records = [] |
| try: |
| with open("data/metadata.jsonl", "r", encoding="utf-8") as f: |
| for line in f: |
| records.append(json.loads(line)) |
| except FileNotFoundError: |
| print("Error: data/metadata.jsonl not found") |
| return |
|
|
| print(f"Loaded {len(records)} records from metadata.jsonl") |
|
|
| |
| dataset = Dataset.from_list(records) |
|
|
| |
| from datasets import Audio |
| dataset = dataset.cast_column("audio", Audio(decode=False)) |
|
|
| print("\nDataset info:") |
| print(f"- Number of samples: {len(dataset)}") |
| print(f"- Features: {dataset.features}") |
|
|
| |
| print("\nFirst 3 examples:") |
| for i, example in enumerate(dataset.select(range(3))): |
| print(f"\n{i+1}. Word: {example['word']}") |
| print(f" IPA: {example['ipa']}") |
| audio = example['audio'] |
| if audio: |
| print(f" Audio path: {audio.get('path', 'N/A')}") |
| if audio.get('bytes'): |
| print(f" Audio bytes: {len(audio['bytes'])} bytes") |
| else: |
| print(" Audio loaded successfully") |
|
|
| return dataset |
|
|
|
|
| if __name__ == "__main__": |
| print("Testing Hugging Face dataset compatibility...") |
| print("=" * 50) |
|
|
| dataset = test_local_dataset() |
|
|
| if dataset: |
| print(f"\n✓ Dataset successfully loaded with {len(dataset)} examples") |
| print("✓ Audio files are properly loaded as Audio features") |
| else: |
| print("✗ Failed to load dataset") |