| import datasets
|
| import lhotse
|
| import torch
|
| import torchaudio
|
| import io
|
| import subprocess
|
|
|
| class YodasPerfectLoader(datasets.GeneratorBasedBuilder):
|
| def _info(self):
|
| return datasets.DatasetInfo(
|
| features=datasets.Features({
|
| "id": datasets.Value("string"),
|
| "audio": datasets.Audio(sampling_rate=16000),
|
| "text": datasets.Value("string"),
|
| }),
|
| )
|
|
|
| def _split_generators(self, dl_manager):
|
|
|
| manifest = dl_manager.download("yodas_format1_cuts_perfect.jsonl.gz")
|
| return [datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": manifest})]
|
|
|
| def _generate_examples(self, filepath):
|
| cuts = lhotse.CutSet.from_file(filepath)
|
| for cut in cuts:
|
| try:
|
|
|
| cmd = cut.recording.sources[0].source
|
| process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
| stdout, _ = process.communicate()
|
|
|
| buffer = io.BytesIO(stdout)
|
| waveform, _ = torchaudio.load(buffer)
|
|
|
| yield cut.id, {
|
| "id": cut.id,
|
| "audio": {"array": waveform.numpy().squeeze(), "sampling_rate": 16000},
|
| "text": cut.supervisions[0].text if cut.supervisions else ""
|
| }
|
| except Exception:
|
| continue |