| |
|
| | import os |
| | import datasets |
| |
|
| | class AudioTextDataset(datasets.GeneratorBasedBuilder): |
| | VERSION = datasets.Version("1.0.0") |
| | |
| | def _info(self): |
| | return datasets.DatasetInfo( |
| | features=datasets.Features({ |
| | "audio": datasets.Audio(sampling_rate=22050), |
| | "text": datasets.Value("string") |
| | }) |
| | ) |
| | |
| | def _split_generators(self, dl_manager): |
| | return [ |
| | datasets.SplitGenerator( |
| | name=datasets.Split.TRAIN, |
| | gen_kwargs={"split": "train"} |
| | ) |
| | ] |
| | |
| | def _generate_examples(self, split): |
| | audio_dir = os.path.join(os.path.dirname(__file__), "audio") |
| | audio_files = sorted([f for f in os.listdir(audio_dir) if f.endswith(".wav")]) |
| | |
| | |
| | text_mapping = {} |
| | mapping_path = os.path.join(os.path.dirname(__file__), "mapping.txt") |
| | with open(mapping_path, "r", encoding="utf-8") as f: |
| | for line in f: |
| | parts = line.strip().split("\t") |
| | if len(parts) == 2: |
| | audio_file, text = parts |
| | text_mapping[audio_file] = text |
| | |
| | for idx, audio_file in enumerate(audio_files): |
| | if audio_file in text_mapping: |
| | yield idx, { |
| | "audio": os.path.join(audio_dir, audio_file), |
| | "text": text_mapping[audio_file] |
| | } |
| | |