KELONMYOSA
commited on
Commit
•
ded9e91
1
Parent(s):
745f9e9
load script
Browse files
dusha.py
CHANGED
@@ -24,8 +24,8 @@ class Dusha(datasets.GeneratorBasedBuilder):
|
|
24 |
description=_DESCRIPTION,
|
25 |
features=datasets.Features(
|
26 |
{
|
27 |
-
"
|
28 |
-
"audio": datasets.
|
29 |
"label": datasets.Value("string"),
|
30 |
}
|
31 |
),
|
@@ -35,30 +35,32 @@ class Dusha(datasets.GeneratorBasedBuilder):
|
|
35 |
|
36 |
def _split_generators(self, dl_manager):
|
37 |
metadata = dl_manager.download(_METADATA_URL)
|
38 |
-
archive = dl_manager.
|
39 |
return [datasets.SplitGenerator(
|
40 |
-
name=datasets.Split.
|
41 |
gen_kwargs={
|
42 |
-
"audio_files":
|
43 |
"metadata": metadata},
|
44 |
)]
|
45 |
|
46 |
def _generate_examples(self, audio_files, metadata: str):
|
47 |
-
examples =
|
48 |
|
49 |
with open(metadata, encoding="utf-8") as f:
|
50 |
csv_reader = csv.reader(f, delimiter=",", skipinitialspace=True)
|
51 |
next(csv_reader)
|
52 |
for row in csv_reader:
|
53 |
audio_path, label = row
|
|
|
|
|
|
|
54 |
res = dict()
|
55 |
-
res["
|
|
|
56 |
res["label"] = label
|
57 |
-
examples
|
58 |
|
59 |
key = 0
|
60 |
-
for
|
61 |
-
|
62 |
-
|
63 |
-
yield key, {**examples[path], "audio": audio}
|
64 |
-
key += 1
|
|
|
24 |
description=_DESCRIPTION,
|
25 |
features=datasets.Features(
|
26 |
{
|
27 |
+
"file": datasets.Value("string"),
|
28 |
+
"audio": datasets.Audio(sampling_rate=16_000),
|
29 |
"label": datasets.Value("string"),
|
30 |
}
|
31 |
),
|
|
|
35 |
|
36 |
def _split_generators(self, dl_manager):
|
37 |
metadata = dl_manager.download(_METADATA_URL)
|
38 |
+
archive = dl_manager.download_and_extract(_DATA_URL)
|
39 |
return [datasets.SplitGenerator(
|
40 |
+
name=datasets.Split.ALL,
|
41 |
gen_kwargs={
|
42 |
+
"audio_files": archive,
|
43 |
"metadata": metadata},
|
44 |
)]
|
45 |
|
46 |
def _generate_examples(self, audio_files, metadata: str):
|
47 |
+
examples = list()
|
48 |
|
49 |
with open(metadata, encoding="utf-8") as f:
|
50 |
csv_reader = csv.reader(f, delimiter=",", skipinitialspace=True)
|
51 |
next(csv_reader)
|
52 |
for row in csv_reader:
|
53 |
audio_path, label = row
|
54 |
+
full_audio_path = os.path.join(audio_files, audio_path)
|
55 |
+
with open(full_audio_path) as audio_file:
|
56 |
+
audio = {"path": full_audio_path, "bytes": audio_file.read()}
|
57 |
res = dict()
|
58 |
+
res["file"] = audio_path.split("/")[1]
|
59 |
+
res["audio"] = audio
|
60 |
res["label"] = label
|
61 |
+
examples.append(res)
|
62 |
|
63 |
key = 0
|
64 |
+
for example in examples:
|
65 |
+
yield key, example
|
66 |
+
key += 1
|
|
|
|