Anjaly commited on
Commit
3f22d1e
1 Parent(s): d23f190

supporting audio zip files

Browse files
Files changed (1) hide show
  1. snow-mountain.py +15 -15
snow-mountain.py CHANGED
@@ -80,7 +80,7 @@ class Test(datasets.GeneratorBasedBuilder):
80
  features = datasets.Features(
81
  {
82
  "sentence": datasets.Value("string"),
83
- # "audio": datasets.features.Audio(sampling_rate=16_000),
84
  "path": datasets.Value("string"),
85
  }
86
  )
@@ -137,22 +137,22 @@ class Test(datasets.GeneratorBasedBuilder):
137
  data_df = pd.read_csv(f,sep=',')
138
  audio_data = {}
139
  for index,row in data_df.iterrows():
140
- # audio = row['path'].split('/')[-1]
141
- # if audio in audio_data:
142
- # content = audio_data[audio]
143
- # else:
144
- # zip_url = '/'.join(row["path"].split('/')[:-1])+'.zip'
145
- # archive_path = dl_manager.download(zip_url)
146
- # for path, file in dl_manager.iter_archive(archive_path):
147
- # audio_ = path.split('/')[-1]
148
- # if audio_ not in audio_data:
149
- # content = file.read()
150
- # audio_data[audio_] = content
151
- # if audio in audio_data:
152
- # content = audio_data[audio]
153
  yield key, {
154
  "sentence": row["sentence"],
155
  "path": row["path"],
156
- # "audio":{"path": row["path"], "bytes": content}
157
  }
158
  key+=1
 
80
  features = datasets.Features(
81
  {
82
  "sentence": datasets.Value("string"),
83
+ "audio": datasets.features.Audio(sampling_rate=16_000),
84
  "path": datasets.Value("string"),
85
  }
86
  )
 
137
  data_df = pd.read_csv(f,sep=',')
138
  audio_data = {}
139
  for index,row in data_df.iterrows():
140
+ audio = row['path'].split('/')[-1]
141
+ if audio in audio_data:
142
+ content = audio_data[audio]
143
+ else:
144
+ zip_url = '/'.join(row["path"].split('/')[:-1])+'.zip'
145
+ archive_path = dl_manager.download(zip_url)
146
+ for path, file in dl_manager.iter_archive(archive_path):
147
+ audio_ = path.split('/')[-1]
148
+ if audio_ not in audio_data:
149
+ content = file.read()
150
+ audio_data[audio_] = content
151
+ if audio in audio_data:
152
+ content = audio_data[audio]
153
  yield key, {
154
  "sentence": row["sentence"],
155
  "path": row["path"],
156
+ "audio":{"path": row["path"], "bytes": content}
157
  }
158
  key+=1