RodrigoLimaRFL commited on
Commit
560a88d
·
verified ·
1 Parent(s): 586bb9c

Update NURC-SP_ENTOA_TTS.py

Browse files
Files changed (1) hide show
  1. NURC-SP_ENTOA_TTS.py +61 -31
NURC-SP_ENTOA_TTS.py CHANGED
@@ -2,6 +2,8 @@ import csv
2
  import datasets
3
  from datasets import BuilderConfig, GeneratorBasedBuilder, DatasetInfo, SplitGenerator, Split
4
 
 
 
5
  _PROMPTS_URLS = {
6
  "dev": "automatic/validation.csv",
7
  "train": "automatic/train.csv",
@@ -22,11 +24,13 @@ _PATH_TO_CLIPS = {
22
  "train": "train",
23
  }
24
 
 
25
  class NurcSPConfig(BuilderConfig):
26
  def __init__(self, prompts_type="original", **kwargs):
27
  super().__init__(**kwargs)
28
  self.prompts_type = prompts_type
29
 
 
30
  class NurcSPDataset(GeneratorBasedBuilder):
31
  BUILDER_CONFIGS = [
32
  NurcSPConfig(name="original", description="Original audio prompts", prompts_type="original"),
@@ -58,52 +62,78 @@ class NurcSPDataset(GeneratorBasedBuilder):
58
  )
59
 
60
  def _split_generators(self, dl_manager):
61
- prompts_urls = _PROMPTS_URLS if self.config.prompts_type == "original" else _PROMPTS_FILTERED_URLS
62
-
63
- # Download the prompts CSV files and audio archive
64
- prompts_path = dl_manager.download_and_extract(prompts_urls)
65
- archive = dl_manager.download_and_extract(_ARCHIVES)
 
 
66
 
67
- # Return split generators
68
  return [
69
  SplitGenerator(
70
- name=Split.TRAIN,
71
  gen_kwargs={
72
- "prompts_path": prompts_path["train"],
73
- "path_to_clips": _PATH_TO_CLIPS["train"],
74
- "audio_files": archive["train"],
75
  }
76
  ),
77
  SplitGenerator(
78
- name=Split.VALIDATION, # Changed from Split.VALIDATION to match error message
79
  gen_kwargs={
80
- "prompts_path": prompts_path["dev"],
81
- "path_to_clips": _PATH_TO_CLIPS["dev"],
82
- "audio_files": archive["dev"],
83
  }
84
  ),
85
  ]
86
 
87
  def _generate_examples(self, prompts_path, path_to_clips, audio_files):
88
- # Load CSV data
89
  examples = {}
90
- with open(prompts_path, "r", encoding='utf-8') as f:
91
  csv_reader = csv.DictReader(f)
92
  for row in csv_reader:
93
- examples[row['file_path']] = {
94
- key: row[key]
95
- for key in row.keys()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  }
97
-
98
- # Process audio files
99
  id_ = 0
100
- for root, _, files in datasets.utils.py_utils.walk(audio_files):
101
- if path_to_clips in root:
102
- for fname in files:
103
- file_path = f"{path_to_clips}/{fname}"
104
- if file_path in examples:
105
- full_path = f"{root}/{fname}"
106
- with open(full_path, "rb") as audio_file:
107
- audio = {"path": file_path, "bytes": audio_file.read()}
108
- yield id_, {**examples[file_path], "audio": audio}
109
- id_ += 1
 
2
  import datasets
3
  from datasets import BuilderConfig, GeneratorBasedBuilder, DatasetInfo, SplitGenerator, Split
4
 
5
+
6
+
7
  _PROMPTS_URLS = {
8
  "dev": "automatic/validation.csv",
9
  "train": "automatic/train.csv",
 
24
  "train": "train",
25
  }
26
 
27
+
28
  class NurcSPConfig(BuilderConfig):
29
  def __init__(self, prompts_type="original", **kwargs):
30
  super().__init__(**kwargs)
31
  self.prompts_type = prompts_type
32
 
33
+
34
  class NurcSPDataset(GeneratorBasedBuilder):
35
  BUILDER_CONFIGS = [
36
  NurcSPConfig(name="original", description="Original audio prompts", prompts_type="original"),
 
62
  )
63
 
64
  def _split_generators(self, dl_manager):
65
+ prompts_urls = _PROMPTS_URLS # Default to original prompts URLs
66
+
67
+ if self.config.prompts_type == "filtered":
68
+ prompts_urls = _PROMPTS_FILTERED_URLS
69
+
70
+ prompts_path = dl_manager.download(prompts_urls)
71
+ archive = dl_manager.download(_ARCHIVES)
72
 
 
73
  return [
74
  SplitGenerator(
75
+ name=Split.VALIDATION,
76
  gen_kwargs={
77
+ "prompts_path": prompts_path["dev"],
78
+ "path_to_clips": _PATH_TO_CLIPS["dev"],
79
+ "audio_files": dl_manager.iter_archive(archive["dev"]),
80
  }
81
  ),
82
  SplitGenerator(
83
+ name=Split.TRAIN,
84
  gen_kwargs={
85
+ "prompts_path": prompts_path["train"],
86
+ "path_to_clips": _PATH_TO_CLIPS["train"],
87
+ "audio_files": dl_manager.iter_archive(archive["train"]),
88
  }
89
  ),
90
  ]
91
 
92
  def _generate_examples(self, prompts_path, path_to_clips, audio_files):
 
93
  examples = {}
94
+ with open(prompts_path, "r") as f:
95
  csv_reader = csv.DictReader(f)
96
  for row in csv_reader:
97
+ audio_name = row['audio_name']
98
+ file_path = row['file_path']
99
+ text = row['text']
100
+ start_time = row['start_time']
101
+ end_time = row['end_time']
102
+ duration = row['duration']
103
+ quality = row['quality']
104
+ speech_genre = row['speech_genre']
105
+ speech_style = row['speech_style']
106
+ variety = row['variety']
107
+ accent = row['accent']
108
+ sex = row['sex']
109
+ age_range = row['age_range']
110
+ num_speakers = row['num_speakers']
111
+ speaker_id = row['speaker_id']
112
+ examples[file_path] = {
113
+ "audio_name": audio_name,
114
+ "file_path": file_path,
115
+ "text": text,
116
+ "start_time": start_time,
117
+ "end_time": end_time,
118
+ "duration": duration,
119
+ "quality": quality,
120
+ "speech_genre": speech_genre,
121
+ "speech_style": speech_style,
122
+ "variety": variety,
123
+ "accent": accent,
124
+ "sex": sex,
125
+ "age_range": age_range,
126
+ "num_speakers": num_speakers,
127
+ "speaker_id": speaker_id,
128
  }
129
+ inside_clips_dir = False
 
130
  id_ = 0
131
+ for path, f in audio_files:
132
+ if path.startswith(path_to_clips):
133
+ inside_clips_dir = True
134
+ if path in examples:
135
+ audio = {"path": path, "bytes": f.read()}
136
+ yield id_, {**examples[path], "audio": audio}
137
+ id_ += 1
138
+ elif inside_clips_dir:
139
+ break