add AudioFolderDataset

This commit is contained in:
iclementine 2020-10-15 23:15:27 +08:00
parent 53d0382fc7
commit 6aa7af1aa4
2 changed files with 28 additions and 0 deletions

6
.gitignore vendored
View File

@ -1,3 +1,9 @@
# IDES
*.wpr
*.wpu
*.udb
*.ann
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

22
parakeet/data/datasets.py Normal file
View File

@ -0,0 +1,22 @@
from paddle.io import Dataset
from os import listdir
from os.path import splitext, join
import librosa
class AudioFolderDataset(Dataset):
def __init__(self, path, sample_rate, extension="wav"):
self.root = path
self.sample_rate = sample_rate
self.extension = extension
self.file_names = [join(self.root, x) for x in listdir(self.root) \
if splitext(x)[-1] == self.extension]
self.length = len(self.file_names)
def __len__(self):
return self.length
def __getitem__(self, i):
file_name = self.file_names[i]
y, sr = librosa.load(file_name, sr=self.sample_rate) # pylint: disable=unused-variable
return y