Datasets:
Languages:
Portuguese
License:
Update NURC-SP_Corpus_Minimo.py
Browse files- NURC-SP_Corpus_Minimo.py +80 -80
NURC-SP_Corpus_Minimo.py
CHANGED
|
@@ -1,80 +1,80 @@
|
|
| 1 |
-
import csv
|
| 2 |
-
import datasets
|
| 3 |
-
from datasets import BuilderConfig, GeneratorBasedBuilder, DatasetInfo, SplitGenerator, Split
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
_PROMPTS_URLS = {
|
| 8 |
-
"
|
| 9 |
-
}
|
| 10 |
-
|
| 11 |
-
_ARCHIVES = {
|
| 12 |
-
"
|
| 13 |
-
}
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
class NurcSPConfig(BuilderConfig):
|
| 17 |
-
def __init__(self, prompts_type="original", **kwargs):
|
| 18 |
-
super().__init__(**kwargs)
|
| 19 |
-
self.prompts_type = prompts_type
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
class NurcSPDataset(GeneratorBasedBuilder):
|
| 23 |
-
def _info(self):
|
| 24 |
-
return DatasetInfo(
|
| 25 |
-
features=datasets.Features(
|
| 26 |
-
{
|
| 27 |
-
"path": datasets.Value("string"),
|
| 28 |
-
"name": datasets.Value("string"),
|
| 29 |
-
"speaker": datasets.Value("string"),
|
| 30 |
-
"start_time": datasets.Value("string"),
|
| 31 |
-
"end_time": datasets.Value("string"),
|
| 32 |
-
"normalized_text": datasets.Value("string"),
|
| 33 |
-
"text": datasets.Value("string"),
|
| 34 |
-
"audio": datasets.Audio(sampling_rate=16_000),
|
| 35 |
-
}
|
| 36 |
-
)
|
| 37 |
-
)
|
| 38 |
-
|
| 39 |
-
def _split_generators(self, dl_manager):
|
| 40 |
-
prompts_path = dl_manager.download(_PROMPTS_URLS)
|
| 41 |
-
archive = dl_manager.download(_ARCHIVES)
|
| 42 |
-
|
| 43 |
-
return [
|
| 44 |
-
{
|
| 45 |
-
"prompts_path": prompts_path["
|
| 46 |
-
"audio_files": dl_manager.iter_archive(archive["
|
| 47 |
-
}
|
| 48 |
-
]
|
| 49 |
-
|
| 50 |
-
def _generate_examples(self, prompts_path, path_to_clips, audio_files):
|
| 51 |
-
examples = {}
|
| 52 |
-
with open(prompts_path, "r") as f:
|
| 53 |
-
csv_reader = csv.DictReader(f)
|
| 54 |
-
for row in csv_reader:
|
| 55 |
-
path = row['path']
|
| 56 |
-
name = row['name']
|
| 57 |
-
speaker = row['speaker']
|
| 58 |
-
start_time = row['start_time']
|
| 59 |
-
end_time = row['end_time']
|
| 60 |
-
normalized_text = row['normalized_text']
|
| 61 |
-
text = row['text']
|
| 62 |
-
examples[path] = {
|
| 63 |
-
"name": name,
|
| 64 |
-
"speaker": speaker,
|
| 65 |
-
"start_time": start_time,
|
| 66 |
-
"end_time": end_time,
|
| 67 |
-
"normalized_text": normalized_text,
|
| 68 |
-
"text": text,
|
| 69 |
-
}
|
| 70 |
-
inside_clips_dir = False
|
| 71 |
-
id_ = 0
|
| 72 |
-
for path, f in audio_files:
|
| 73 |
-
if path.startswith(path_to_clips):
|
| 74 |
-
inside_clips_dir = True
|
| 75 |
-
if path in examples:
|
| 76 |
-
audio = {"path": path, "bytes": f.read()}
|
| 77 |
-
yield id_, {**examples[path], "audio": audio}
|
| 78 |
-
id_ += 1
|
| 79 |
-
elif inside_clips_dir:
|
| 80 |
-
break
|
|
|
|
| 1 |
+
import csv
|
| 2 |
+
import datasets
|
| 3 |
+
from datasets import BuilderConfig, GeneratorBasedBuilder, DatasetInfo, SplitGenerator, Split
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
_PROMPTS_URLS = {
|
| 8 |
+
"def": "segmented_audios.csv",
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
_ARCHIVES = {
|
| 12 |
+
"def": "nurc-sp_corpus_minimo.tar.gz",
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
class NurcSPConfig(BuilderConfig):
|
| 17 |
+
def __init__(self, prompts_type="original", **kwargs):
|
| 18 |
+
super().__init__(**kwargs)
|
| 19 |
+
self.prompts_type = prompts_type
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
class NurcSPDataset(GeneratorBasedBuilder):
|
| 23 |
+
def _info(self):
|
| 24 |
+
return DatasetInfo(
|
| 25 |
+
features=datasets.Features(
|
| 26 |
+
{
|
| 27 |
+
"path": datasets.Value("string"),
|
| 28 |
+
"name": datasets.Value("string"),
|
| 29 |
+
"speaker": datasets.Value("string"),
|
| 30 |
+
"start_time": datasets.Value("string"),
|
| 31 |
+
"end_time": datasets.Value("string"),
|
| 32 |
+
"normalized_text": datasets.Value("string"),
|
| 33 |
+
"text": datasets.Value("string"),
|
| 34 |
+
"audio": datasets.Audio(sampling_rate=16_000),
|
| 35 |
+
}
|
| 36 |
+
)
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
def _split_generators(self, dl_manager):
|
| 40 |
+
prompts_path = dl_manager.download(_PROMPTS_URLS)
|
| 41 |
+
archive = dl_manager.download(_ARCHIVES)
|
| 42 |
+
|
| 43 |
+
return [
|
| 44 |
+
{
|
| 45 |
+
"prompts_path": prompts_path["def"],
|
| 46 |
+
"audio_files": dl_manager.iter_archive(archive["def"]),
|
| 47 |
+
}
|
| 48 |
+
]
|
| 49 |
+
|
| 50 |
+
def _generate_examples(self, prompts_path, path_to_clips, audio_files):
|
| 51 |
+
examples = {}
|
| 52 |
+
with open(prompts_path, "r") as f:
|
| 53 |
+
csv_reader = csv.DictReader(f)
|
| 54 |
+
for row in csv_reader:
|
| 55 |
+
path = row['path']
|
| 56 |
+
name = row['name']
|
| 57 |
+
speaker = row['speaker']
|
| 58 |
+
start_time = row['start_time']
|
| 59 |
+
end_time = row['end_time']
|
| 60 |
+
normalized_text = row['normalized_text']
|
| 61 |
+
text = row['text']
|
| 62 |
+
examples[path] = {
|
| 63 |
+
"name": name,
|
| 64 |
+
"speaker": speaker,
|
| 65 |
+
"start_time": start_time,
|
| 66 |
+
"end_time": end_time,
|
| 67 |
+
"normalized_text": normalized_text,
|
| 68 |
+
"text": text,
|
| 69 |
+
}
|
| 70 |
+
inside_clips_dir = False
|
| 71 |
+
id_ = 0
|
| 72 |
+
for path, f in audio_files:
|
| 73 |
+
if path.startswith(path_to_clips):
|
| 74 |
+
inside_clips_dir = True
|
| 75 |
+
if path in examples:
|
| 76 |
+
audio = {"path": path, "bytes": f.read()}
|
| 77 |
+
yield id_, {**examples[path], "audio": audio}
|
| 78 |
+
id_ += 1
|
| 79 |
+
elif inside_clips_dir:
|
| 80 |
+
break
|