File size: 1,025 Bytes
6835659 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | import json
from pathlib import Path
class AudioCapsLoader:
def __init__(self, base_dir: str = "data/audiocaps"):
self.base_dir = Path(base_dir)
self.samples_file = self.base_dir / "samples.json"
def load(self):
if not self.samples_file.exists():
raise FileNotFoundError(f"Missing {self.samples_file}")
with self.samples_file.open("r", encoding="utf-8") as f:
data = json.load(f)
samples = []
for item in data:
audio_path = self.base_dir / item["audio"]
if not audio_path.exists():
print(f"⚠️ Missing audio file: {audio_path}")
continue
samples.append(
{
"id": item["id"],
"caption": item["caption"],
"image_path": None,
"audio_path": audio_path,
}
)
print(f"AudioCaps loader finished. Samples: {len(samples)}")
return samples |