| | |
| | | |
| | | import random |
| | | import numpy as np |
| | | import soundfile |
| | | import librosa |
| | | from typeguard import check_argument_types |
| | | import librosa |
| | | |
| | | import torch |
| | | import torchaudio |
| | |
| | | dest_sample_rate: int = 16000, |
| | | speed_perturb: Union[list, tuple] = None, |
| | | ): |
| | | assert check_argument_types() |
| | | self.fname = fname |
| | | self.dtype = dtype |
| | | self.always_2d = always_2d |
| | |
| | | def __getitem__(self, key): |
| | | wav = self.data[key] |
| | | if self.normalize: |
| | | # soundfile.read normalizes data to [-1,1] if dtype is not given |
| | | # librosa.load normalizes data to [-1,1] if dtype is not given |
| | | array, rate = librosa.load( |
| | | wav, sr=self.dest_sample_rate, mono=self.always_2d |
| | | ) |
| | |
| | | format="wav", |
| | | dtype=None, |
| | | ): |
| | | assert check_argument_types() |
| | | self.dir = Path(outdir) |
| | | self.dir.mkdir(parents=True, exist_ok=True) |
| | | scpfile = Path(scpfile) |