Datasets:
Update NURC-SP_ENTOA_TTS.py
Browse files- NURC-SP_ENTOA_TTS.py +49 -38
NURC-SP_ENTOA_TTS.py
CHANGED
|
@@ -1,8 +1,11 @@
|
|
| 1 |
import csv
|
| 2 |
import datasets
|
| 3 |
from datasets import BuilderConfig, GeneratorBasedBuilder, DatasetInfo, SplitGenerator, Split
|
|
|
|
| 4 |
|
| 5 |
-
|
|
|
|
|
|
|
| 6 |
|
| 7 |
_PROMPTS_URLS = {
|
| 8 |
"dev": "automatic/validation.csv",
|
|
@@ -24,13 +27,11 @@ _PATH_TO_CLIPS = {
|
|
| 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,13 +63,19 @@ class NurcSPDataset(GeneratorBasedBuilder):
|
|
| 62 |
)
|
| 63 |
|
| 64 |
def _split_generators(self, dl_manager):
|
| 65 |
-
|
| 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(
|
|
@@ -90,50 +97,54 @@ class NurcSPDataset(GeneratorBasedBuilder):
|
|
| 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 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import csv
|
| 2 |
import datasets
|
| 3 |
from datasets import BuilderConfig, GeneratorBasedBuilder, DatasetInfo, SplitGenerator, Split
|
| 4 |
+
import logging
|
| 5 |
|
| 6 |
+
# Set up logging
|
| 7 |
+
logging.basicConfig(level=logging.INFO)
|
| 8 |
+
logger = logging.getLogger(__name__)
|
| 9 |
|
| 10 |
_PROMPTS_URLS = {
|
| 11 |
"dev": "automatic/validation.csv",
|
|
|
|
| 27 |
"train": "train",
|
| 28 |
}
|
| 29 |
|
|
|
|
| 30 |
class NurcSPConfig(BuilderConfig):
|
| 31 |
def __init__(self, prompts_type="original", **kwargs):
|
| 32 |
super().__init__(**kwargs)
|
| 33 |
self.prompts_type = prompts_type
|
| 34 |
|
|
|
|
| 35 |
class NurcSPDataset(GeneratorBasedBuilder):
|
| 36 |
BUILDER_CONFIGS = [
|
| 37 |
NurcSPConfig(name="original", description="Original audio prompts", prompts_type="original"),
|
|
|
|
| 63 |
)
|
| 64 |
|
| 65 |
def _split_generators(self, dl_manager):
|
| 66 |
+
logger.info(f"Using prompts_type: {self.config.prompts_type}")
|
| 67 |
+
|
| 68 |
+
prompts_urls = _PROMPTS_URLS
|
| 69 |
if self.config.prompts_type == "filtered":
|
| 70 |
prompts_urls = _PROMPTS_FILTERED_URLS
|
| 71 |
+
|
| 72 |
+
logger.info(f"Downloading prompts from: {prompts_urls}")
|
| 73 |
prompts_path = dl_manager.download(prompts_urls)
|
| 74 |
+
logger.info(f"Downloaded prompts to: {prompts_path}")
|
| 75 |
+
|
| 76 |
+
logger.info(f"Downloading archives from: {_ARCHIVES}")
|
| 77 |
archive = dl_manager.download(_ARCHIVES)
|
| 78 |
+
logger.info(f"Downloaded archives to: {archive}")
|
| 79 |
|
| 80 |
return [
|
| 81 |
SplitGenerator(
|
|
|
|
| 97 |
]
|
| 98 |
|
| 99 |
def _generate_examples(self, prompts_path, path_to_clips, audio_files):
|
| 100 |
+
logger.info(f"Generating examples from prompts_path: {prompts_path}")
|
| 101 |
+
logger.info(f"Looking for clips in: {path_to_clips}")
|
| 102 |
+
|
| 103 |
examples = {}
|
| 104 |
+
example_count = 0
|
| 105 |
+
|
| 106 |
+
# Read CSV file
|
| 107 |
with open(prompts_path, "r") as f:
|
| 108 |
csv_reader = csv.DictReader(f)
|
| 109 |
for row in csv_reader:
|
| 110 |
+
examples[row['file_path']] = {
|
| 111 |
+
"audio_name": row['audio_name'],
|
| 112 |
+
"file_path": row['file_path'],
|
| 113 |
+
"text": row['text'],
|
| 114 |
+
"start_time": row['start_time'],
|
| 115 |
+
"end_time": row['end_time'],
|
| 116 |
+
"duration": row['duration'],
|
| 117 |
+
"quality": row['quality'],
|
| 118 |
+
"speech_genre": row['speech_genre'],
|
| 119 |
+
"speech_style": row['speech_style'],
|
| 120 |
+
"variety": row['variety'],
|
| 121 |
+
"accent": row['accent'],
|
| 122 |
+
"sex": row['sex'],
|
| 123 |
+
"age_range": row['age_range'],
|
| 124 |
+
"num_speakers": row['num_speakers'],
|
| 125 |
+
"speaker_id": row['speaker_id'],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
}
|
| 127 |
+
example_count += 1
|
| 128 |
+
|
| 129 |
+
logger.info(f"Found {example_count} examples in CSV")
|
| 130 |
+
|
| 131 |
inside_clips_dir = False
|
| 132 |
id_ = 0
|
| 133 |
+
matched_files = 0
|
| 134 |
+
|
| 135 |
for path, f in audio_files:
|
| 136 |
+
logger.debug(f"Processing archive file: {path}")
|
| 137 |
if path.startswith(path_to_clips):
|
| 138 |
inside_clips_dir = True
|
| 139 |
+
logger.debug(f"Found file in clips directory: {path}")
|
| 140 |
if path in examples:
|
| 141 |
audio = {"path": path, "bytes": f.read()}
|
| 142 |
+
matched_files += 1
|
| 143 |
yield id_, {**examples[path], "audio": audio}
|
| 144 |
id_ += 1
|
| 145 |
elif inside_clips_dir:
|
| 146 |
+
break
|
| 147 |
+
|
| 148 |
+
logger.info(f"Matched {matched_files} audio files with CSV entries")
|
| 149 |
+
if matched_files == 0:
|
| 150 |
+
logger.warning("No audio files were matched with CSV entries!")
|