-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathSpeechDataGenerator.py
35 lines (27 loc) · 1006 Bytes
/
SpeechDataGenerator.py
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Jul 20 14:09:31 2019
@author: Krishna
"""
import numpy as np
import torch
from utils import utils
class SpeechDataGenerator():
"""Speech dataset."""
def __init__(self, manifest, mode):
"""
Read the textfile and get the paths
"""
self.mode=mode
self.audio_links = [line.rstrip('\n').split(' ')[0] for line in open(manifest)]
self.labels = [int(line.rstrip('\n').split(' ')[1]) for line in open(manifest)]
def __len__(self):
return len(self.audio_links)
def __getitem__(self, idx):
audio_link =self.audio_links[idx]
class_id = self.labels[idx]
#lang_label=lang_id[self.audio_links[idx].split('/')[-2]]
spec = utils.load_data(audio_link,mode=self.mode)
sample = {'features': torch.from_numpy(np.ascontiguousarray(spec)), 'labels': torch.from_numpy(np.ascontiguousarray(class_id))}
return sample