KELONMYOSA commited on
Commit
ded9e91
1 Parent(s): 745f9e9

load script

Browse files
Files changed (1) hide show
  1. dusha.py +15 -13
dusha.py CHANGED
@@ -24,8 +24,8 @@ class Dusha(datasets.GeneratorBasedBuilder):
24
  description=_DESCRIPTION,
25
  features=datasets.Features(
26
  {
27
- "path": datasets.Value("string"),
28
- "audio": datasets.features.Audio(sampling_rate=16_000),
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.download(_DATA_URL)
39
  return [datasets.SplitGenerator(
40
- name=datasets.Split.TRAIN,
41
  gen_kwargs={
42
- "audio_files": dl_manager.iter_archive(archive),
43
  "metadata": metadata},
44
  )]
45
 
46
  def _generate_examples(self, audio_files, metadata: str):
47
- examples = dict()
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["path"] = os.path.join(audio_files, audio_path)
 
56
  res["label"] = label
57
- examples[audio_path] = res
58
 
59
  key = 0
60
- for path, f in audio_files:
61
- if path in examples:
62
- audio = {"path": path, "bytes": f.read()}
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