jimregan commited on
Commit
e41409d
1 Parent(s): b707341

continue if "val_recordings" missing; support data_dir

Browse files
Files changed (1) hide show
  1. nst.py +14 -3
nst.py CHANGED
@@ -16,6 +16,7 @@
16
 
17
  from pathlib import Path
18
  import json
 
19
 
20
  import datasets
21
  from datasets.tasks import AutomaticSpeechRecognition
@@ -96,8 +97,17 @@ class NSTDataset(datasets.GeneratorBasedBuilder):
96
  # split is hardcoded to 'train' for now; there is a test set, but
97
  # it has not been modernised
98
  def _split_generators(self, dl_manager):
99
- json_dir = dl_manager.download_and_extract(_JSON_URL)
100
- audio_dirs = dl_manager.download_and_extract(_AUDIO_URLS)
 
 
 
 
 
 
 
 
 
101
  return [
102
  datasets.SplitGenerator(
103
  name=datasets.Split.TRAIN,
@@ -119,7 +129,8 @@ class NSTDataset(datasets.GeneratorBasedBuilder):
119
  data = json.load(json_file)
120
  speaker_data = _get_speaker_data(data["info"])
121
  pid = data["pid"]
122
- print(pid)
 
123
  for recording in data["val_recordings"]:
124
  bare_path = recording['file'].replace(".wav", "")
125
  text = recording["text"]
 
16
 
17
  from pathlib import Path
18
  import json
19
+ import os
20
 
21
  import datasets
22
  from datasets.tasks import AutomaticSpeechRecognition
 
97
  # split is hardcoded to 'train' for now; there is a test set, but
98
  # it has not been modernised
99
  def _split_generators(self, dl_manager):
100
+ if hasattr(dl_manager, 'manual_dir'):
101
+ data_dir = os.path.abspath(os.path.expanduser(dl_manager.manual_dir))
102
+ JSON_FILE = _JSON_URL.split("/")[-1]
103
+ AUDIO_FILES = [
104
+ os.path.join(data_dir, a.split("/")[-1]) for a in _AUDIO_URLS
105
+ ]
106
+ json_dir = dl_manager.extract(os.path.join(data_dir, JSON_FILE))
107
+ audio_dirs = dl_manager.extract(AUDIO_FILES)
108
+ else:
109
+ json_dir = dl_manager.download_and_extract(_JSON_URL)
110
+ audio_dirs = dl_manager.download_and_extract(_AUDIO_URLS)
111
  return [
112
  datasets.SplitGenerator(
113
  name=datasets.Split.TRAIN,
 
129
  data = json.load(json_file)
130
  speaker_data = _get_speaker_data(data["info"])
131
  pid = data["pid"]
132
+ if "val_recordings" not in data:
133
+ continue
134
  for recording in data["val_recordings"]:
135
  bare_path = recording['file'].replace(".wav", "")
136
  text = recording["text"]