File size: 4,102 Bytes
96fd80c 09857e0 96fd80c 09857e0 69bf1ce 96fd80c 09857e0 96fd80c 09857e0 96fd80c 09857e0 96fd80c 09857e0 96fd80c 09857e0 96fd80c 09857e0 96fd80c 09857e0 96fd80c 586bb9c bbea063 586bb9c 96fd80c 586bb9c 96fd80c 586bb9c 09857e0 96fd80c 586bb9c 96fd80c 586bb9c 09857e0 96fd80c 586bb9c 96fd80c 586bb9c 96fd80c 586bb9c 09857e0 586bb9c 09857e0 586bb9c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
import csv
import datasets
from datasets import BuilderConfig, GeneratorBasedBuilder, DatasetInfo, SplitGenerator, Split
_PROMPTS_URLS = {
"dev": "automatic/validation.csv",
"train": "automatic/train.csv",
}
_PROMPTS_FILTERED_URLS = {
"dev": "automatic/validation.csv",
"train": "automatic/train.csv",
}
_ARCHIVES = {
"dev": "automatic.tar.gz",
"train": "automatic.tar.gz",
}
_PATH_TO_CLIPS = {
"dev": "validation",
"train": "train",
}
class NurcSPConfig(BuilderConfig):
def __init__(self, prompts_type="original", **kwargs):
super().__init__(**kwargs)
self.prompts_type = prompts_type
class NurcSPDataset(GeneratorBasedBuilder):
BUILDER_CONFIGS = [
NurcSPConfig(name="original", description="Original audio prompts", prompts_type="original"),
NurcSPConfig(name="filtered", description="Filtered audio prompts", prompts_type="filtered"),
]
def _info(self):
return DatasetInfo(
features=datasets.Features(
{
"audio_name": datasets.Value("string"),
"file_path": datasets.Value("string"),
"text": datasets.Value("string"),
"start_time": datasets.Value("string"),
"end_time": datasets.Value("string"),
"duration": datasets.Value("string"),
"quality": datasets.Value("string"),
"speech_genre": datasets.Value("string"),
"speech_style": datasets.Value("string"),
"variety": datasets.Value("string"),
"accent": datasets.Value("string"),
"sex": datasets.Value("string"),
"age_range": datasets.Value("string"),
"num_speakers": datasets.Value("string"),
"speaker_id": datasets.Value("string"),
"audio": datasets.Audio(sampling_rate=16_000),
}
)
)
def _split_generators(self, dl_manager):
prompts_urls = _PROMPTS_URLS if self.config.prompts_type == "original" else _PROMPTS_FILTERED_URLS
# Download the prompts CSV files and audio archive
prompts_path = dl_manager.download_and_extract(prompts_urls)
archive = dl_manager.download_and_extract(_ARCHIVES)
# Return split generators
return [
SplitGenerator(
name=Split.TRAIN,
gen_kwargs={
"prompts_path": prompts_path["train"],
"path_to_clips": _PATH_TO_CLIPS["train"],
"audio_files": archive["train"],
}
),
SplitGenerator(
name=Split.VALIDATION, # Changed from Split.VALIDATION to match error message
gen_kwargs={
"prompts_path": prompts_path["dev"],
"path_to_clips": _PATH_TO_CLIPS["dev"],
"audio_files": archive["dev"],
}
),
]
def _generate_examples(self, prompts_path, path_to_clips, audio_files):
# Load CSV data
examples = {}
with open(prompts_path, "r", encoding='utf-8') as f:
csv_reader = csv.DictReader(f)
for row in csv_reader:
examples[row['file_path']] = {
key: row[key]
for key in row.keys()
}
# Process audio files
id_ = 0
for root, _, files in datasets.utils.py_utils.walk(audio_files):
if path_to_clips in root:
for fname in files:
file_path = f"{path_to_clips}/{fname}"
if file_path in examples:
full_path = f"{root}/{fname}"
with open(full_path, "rb") as audio_file:
audio = {"path": file_path, "bytes": audio_file.read()}
yield id_, {**examples[file_path], "audio": audio}
id_ += 1 |