mirror of
https://github.com/Nighthawk42/soprano-factory.git
synced 2026-08-30 04:30:21 +00:00
18 lines
514 B
Python
18 lines
514 B
Python
import json
|
|
from torch.utils.data import Dataset
|
|
|
|
|
|
class AudioDataset(Dataset):
|
|
def __init__(self, path):
|
|
with open(path, encoding='utf-8') as f:
|
|
self.dataset = json.load(f)
|
|
|
|
def __len__(self):
|
|
return len(self.dataset)
|
|
|
|
def __getitem__(self, idx):
|
|
text, audio = self.dataset[idx]
|
|
# Format: [STOP][TEXT]<text prompt>[START]<audio tokens>[STOP]
|
|
res = f"[STOP][TEXT]{text}[START]{''.join(list(map(lambda x: f'[{x}]', audio)))}[STOP]"
|
|
return res
|