-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathSpeechDataGenerator.py
More file actions
37 lines (27 loc) · 1.08 KB
/
SpeechDataGenerator.py
File metadata and controls
37 lines (27 loc) · 1.08 KB
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
35
36
37
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri May 29 12:16:28 2020
@author: krishna
"""
import numpy as np
import torch
from utils import utility
class SpeechDataGenerator():
"""Speech dataset."""
def __init__(self, manifest):
"""
Read the textfile and get the paths
"""
self.json_links = [line.rstrip('\n').split(' ')[0] for line in open(manifest)]
def __len__(self):
return len(self.json_links)
def __getitem__(self, idx):
json_link =self.json_links[idx]
masked_features,original_feats,final_phn_seq,phn_seq_len = utility.load_data(json_link)
#lang_label=lang_id[self.audio_links[idx].split('/')[-2]]
sample = {'masked_feats': torch.from_numpy(np.ascontiguousarray(masked_features)),
'gt_feats': torch.from_numpy(np.ascontiguousarray(original_feats)),
'phn_seq': torch.from_numpy(np.ascontiguousarray(final_phn_seq)),
'labels_length': torch.from_numpy(np.ascontiguousarray(phn_seq_len))}
return sample