Files
Nighthawk e7ee43de41 Refactor: Centralize config, add OS-aware audio pipeline, and migrate to uv
Major framework modernization and quality-of-life improvements:

- Centralized Configuration: Replaced scattered, hardcoded hyperparameters and paths across all training/inference scripts with a single, documented `config.yaml` and `config_loader.py`.
- OS-Aware Audio Pipeline: Introduced `utils/audio_utils.py` to handle cross-platform audio loading. Automatically routes Windows to a robust `ffmpeg` subprocess to bypass unstable Python audio bindings, while keeping `torchaudio` for Linux.
- Dependency Management: Migrated from `requirements.txt` to `uv` with a fully configured `pyproject.toml`. Explicitly targets Python 3.12 and pulls PyTorch `cu128` wheels by default.
- Dataset Fixes: Restored the missing `dataset_e2e.py` required for proper STFT/GAN decoder training and updated all dataloaders to utilize the new AudioPipeline.
- Documentation & Housekeeping: Overhauled `README.md` with updated workflows, Windows instructions, and `uv` setup. Added a comprehensive `.gitignore` for virtual environments, model weights, and cache files.
2026-02-26 13:58:35 -05:00

39 lines
1.2 KiB
Python

import torch
from torch.utils.data import Dataset
import os
import json
from utils.audio_utils import AudioPipeline
class LJSpeechDataset(Dataset):
def __init__(self, root, sample_rate=32000, mode='train'):
"""
root: path to LJSpeech-1.1 directory
"""
self.root = root
self.sample_rate = sample_rate
self.mode = mode
mode_json = os.path.join(root, f"{mode}.json")
if not os.path.exists(mode_json):
raise FileNotFoundError(f"Dataset JSON not found: {mode_json}")
with open(mode_json, 'r') as f:
self.dataset = json.load(f)
def __len__(self):
return len(self.dataset)
def __getitem__(self, idx):
item = self.dataset[idx]
text, audio_tokens, wav_path = item
# Use the robust OS-aware pipeline to load, convert to mono, and resample
try:
wav, _ = AudioPipeline.load_audio(wav_path, target_sr=self.sample_rate)
except Exception as e:
print(f"Error loading {wav_path}: {e}")
# Fallback to 1 second of silence to prevent the dataloader from crashing the entire run
wav = torch.zeros((1, self.sample_rate))
return wav