PerSets commited on
Commit
1c41ad1
·
1 Parent(s): cbe9218

fix: trying to pair metadata and tarfile audios

Browse files
Files changed (1) hide show
  1. asr_dataset.py +14 -11
asr_dataset.py CHANGED
@@ -99,18 +99,14 @@ class ASRDataset(datasets.GeneratorBasedBuilder):
99
 
100
  def _generate_examples(self, prompts_path, path_to_clips, audio_files):
101
  """Yields examples as (key, example) tuples."""
102
- logger.info('hey there!')
103
- examples = {}
104
  with open(prompts_path, encoding="utf-8") as f:
105
  for row in f:
106
  data = row.strip().split("\t", 1)
107
  file_name = data[0].strip()
108
- audio_path = file_name # "/".join([path_to_clips, file_name])
109
- examples[audio_path] = {
110
- "path": audio_path,
111
- "sentence": data[1],
112
- }
113
- inside_clips_dir = False
114
  id_ = 0
115
 
116
  tar_files = [
@@ -139,8 +135,15 @@ class ASRDataset(datasets.GeneratorBasedBuilder):
139
  for tar_file in tar_files:
140
  with tarfile.open(tar_file, 'r') as tar:
141
  for member in tar.getmembers():
142
- path = member.name #"/".join([path_to_clips, member.name])
 
 
 
143
  audio_file =tar.extractfile(member)
144
- audio = {"path": path, "bytes": audio_file.read()}
145
- yield id_, {**examples[path], "audio": audio}
 
 
 
 
146
  id_ += 1
 
99
 
100
  def _generate_examples(self, prompts_path, path_to_clips, audio_files):
101
  """Yields examples as (key, example) tuples."""
102
+
103
+ sentence_map = {}
104
  with open(prompts_path, encoding="utf-8") as f:
105
  for row in f:
106
  data = row.strip().split("\t", 1)
107
  file_name = data[0].strip()
108
+ sentence_map[audio_path] = sentence
109
+
 
 
 
 
110
  id_ = 0
111
 
112
  tar_files = [
 
135
  for tar_file in tar_files:
136
  with tarfile.open(tar_file, 'r') as tar:
137
  for member in tar.getmembers():
138
+ file_name = member.name #"/".join([path_to_clips, member.name])
139
+
140
+ sentence = sentence_map.get(file_name, "")
141
+
142
  audio_file =tar.extractfile(member)
143
+ audio = {"path": file_name, "bytes": audio_file.read()}
144
+ yield id_, {
145
+ "file_name": file_name,
146
+ "audio": audio,
147
+ "sentence": sentence
148
+ }
149
  id_ += 1