-
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.
feat: add librispeech dataset, add text info option to commonvoice
- Loading branch information
1 parent
c258266
commit b2f3eaf
Showing
6 changed files
with
94 additions
and
10 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,4 +1,5 @@ | ||
from .common_voice_dataset import CommonVoiceDataset | ||
from .ljspeech_dataset import LJSpeechDataset | ||
from .libri_speech_dataset import LibriSpeechDataset | ||
from .lj_speech_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
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,44 @@ | ||
import os | ||
from typing import Callable, Dict, Optional, Tuple, Union | ||
|
||
import torch | ||
from torch import Tensor | ||
from torch.utils.data import Dataset | ||
|
||
|
||
class LibriSpeechDataset(Dataset): | ||
def __init__( | ||
self, | ||
root: str = "./data", | ||
with_info: bool = False, | ||
transforms: Optional[Callable] = None, | ||
): | ||
self.with_info = with_info | ||
self.transforms = transforms | ||
|
||
from datasets import load_dataset | ||
|
||
self.dataset = load_dataset( | ||
"librispeech_asr", | ||
"clean", | ||
split="train.100", | ||
cache_dir=os.path.join(root, "librispeech_dataset"), | ||
) | ||
|
||
def __getitem__( | ||
self, idx: Union[Tensor, int] | ||
) -> Union[Tensor, Tuple[Tensor, Dict]]: | ||
idx = idx.tolist() if torch.is_tensor(idx) else idx # type: ignore | ||
data = self.dataset[idx] | ||
waveform = torch.tensor(data["audio"]["array"]).view(1, -1) | ||
info = dict( | ||
sample_rate=data["audio"]["sampling_rate"], | ||
text=data["text"], | ||
speaker_id=data["speaker_id"], | ||
) | ||
if self.transforms: | ||
waveform = self.transforms(waveform) | ||
return (waveform, info) if self.with_info else waveform | ||
|
||
def __len__(self) -> int: | ||
return len(self.dataset) |
File renamed without changes.
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