flexthink commited on
Commit
00f96ff
1 Parent(s): 4c7bd43
Files changed (1) hide show
  1. audiomnist.py +12 -10
audiomnist.py CHANGED
@@ -23,6 +23,8 @@ import os
23
 
24
  import datasets
25
 
 
 
26
  logger = logging.getLogger(__name__)
27
 
28
  _DESCRIPTION = """\
@@ -96,14 +98,12 @@ class GraphemeToPhoneme(datasets.GeneratorBasedBuilder):
96
  def _split_generator(self, dl_manager, split):
97
  archive_url = self._get_url(split)
98
  archive_path = dl_manager.download_and_extract(archive_url)
99
- archive = dl_manager.iter_archive(archive_url)
100
  meta_url = self._get_meta_url()
101
  meta_file = dl_manager.download(meta_url)
102
  speaker_map = self._get_speaker_map(meta_file)
103
  return datasets.SplitGenerator(
104
  name=split,
105
  gen_kwargs={
106
- "archive": archive,
107
  "archive_path": archive_path,
108
  "speaker_map": speaker_map,
109
  },
@@ -128,8 +128,9 @@ class GraphemeToPhoneme(datasets.GeneratorBasedBuilder):
128
  del result["recordingroom"]
129
  return result
130
 
131
- def _generate_examples(self, archive, archive_path, speaker_map):
132
- for path, sample_file in archive:
 
133
  match = _RE_FILE_NAME.search(path)
134
  if not match:
135
  logger.warn(
@@ -139,12 +140,13 @@ class GraphemeToPhoneme(datasets.GeneratorBasedBuilder):
139
  digit, speaker_id = [
140
  match.group(key) for key in ["digit", "speaker_id"]
141
  ]
142
- sample = {
143
- "digit": digit,
144
- "speaker_id": speaker_id,
145
- "file_name": os.path.join(archive_path, path),
146
- "audio": {"path": path, "bytes": sample_file.read()},
147
- }
 
148
  if speaker_id not in speaker_map:
149
  logger.warn(f"Speaker {speaker_id} not found")
150
  speaker_info = speaker_map[speaker_id]
 
23
 
24
  import datasets
25
 
26
+ from glob import glob
27
+
28
  logger = logging.getLogger(__name__)
29
 
30
  _DESCRIPTION = """\
 
98
  def _split_generator(self, dl_manager, split):
99
  archive_url = self._get_url(split)
100
  archive_path = dl_manager.download_and_extract(archive_url)
 
101
  meta_url = self._get_meta_url()
102
  meta_file = dl_manager.download(meta_url)
103
  speaker_map = self._get_speaker_map(meta_file)
104
  return datasets.SplitGenerator(
105
  name=split,
106
  gen_kwargs={
 
107
  "archive_path": archive_path,
108
  "speaker_map": speaker_map,
109
  },
 
128
  del result["recordingroom"]
129
  return result
130
 
131
+ def _generate_examples(self, archive_path, speaker_map):
132
+ wav_files = glob(os.path.join(archive_path, 'dataset', '**', '*.wav'))
133
+ for path in wav_files:
134
  match = _RE_FILE_NAME.search(path)
135
  if not match:
136
  logger.warn(
 
140
  digit, speaker_id = [
141
  match.group(key) for key in ["digit", "speaker_id"]
142
  ]
143
+ with open(path, 'rb') as wav_file:
144
+ sample = {
145
+ "digit": digit,
146
+ "speaker_id": speaker_id,
147
+ "file_name": os.path.join(archive_path, path),
148
+ "audio": {"path": path, "bytes": wav_file.read()},
149
+ }
150
  if speaker_id not in speaker_map:
151
  logger.warn(f"Speaker {speaker_id} not found")
152
  speaker_info = speaker_map[speaker_id]