-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8701581
commit 85ed396
Showing
5 changed files
with
87 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from .common_voice_dataset import CommonVoiceDataset | ||
from .ljspeech_dataset import LJSpeechDataset | ||
from .wav_dataset import WAVDataset | ||
from .youtube_dataset import YoutubeDataset |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from typing import Callable, Optional, Sequence, Tuple, Union | ||
|
||
import torch | ||
from datasets import interleave_datasets, load_dataset | ||
from torch import Tensor | ||
from torch.utils.data import Dataset | ||
|
||
|
||
class CommonVoiceDataset(Dataset): | ||
def __init__( | ||
self, | ||
root: str = "./data", | ||
languages: Sequence[str] = ["en"], | ||
with_sample_rate: bool = False, | ||
transforms: Optional[Callable] = None, | ||
): | ||
self.root = root | ||
self.with_sample_rate = with_sample_rate | ||
self.transforms = transforms | ||
|
||
self.dataset = interleave_datasets( | ||
[ | ||
load_dataset("common_voice", language, split="train", cache_dir=root) | ||
for language in languages | ||
] | ||
) | ||
|
||
def __getitem__(self, idx: int) -> Union[Tensor, Tuple[Tensor, Tensor]]: | ||
data = self.dataset[idx] | ||
waveform = torch.tensor(data["audio"]["array"]).view(1, -1) | ||
sample_rate = data["audio"]["sampling_rate"] | ||
|
||
if self.transforms: | ||
waveform = self.transforms(waveform) | ||
return (waveform, sample_rate) if self.with_sample_rate else waveform | ||
|
||
def __len__(self) -> int: | ||
return len(self.dataset) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters