yangwang825 commited on
Commit
d5dd186
·
verified ·
1 Parent(s): d270516

Update mswc.py

Browse files
Files changed (1) hide show
  1. mswc.py +28 -1
mswc.py CHANGED
@@ -163,4 +163,31 @@ class MSWC(datasets.GeneratorBasedBuilder):
163
  "audio": audio_path,
164
  "keyword": Path(audio_path).stem.split('_')[0],
165
  "label": Path(audio_path).stem.split('_')[0],
166
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
163
  "audio": audio_path,
164
  "keyword": Path(audio_path).stem.split('_')[0],
165
  "label": Path(audio_path).stem.split('_')[0],
166
+ }
167
+
168
+
169
+ def fast_scandir(path: str, exts: tp.List[str], recursive: bool = False):
170
+ # Scan files recursively faster than glob
171
+ # From github.com/drscotthawley/aeiou/blob/main/aeiou/core.py
172
+ subfolders, files = [], []
173
+
174
+ try: # hope to avoid 'permission denied' by this try
175
+ for f in os.scandir(path):
176
+ try: # 'hope to avoid too many levels of symbolic links' error
177
+ if f.is_dir():
178
+ subfolders.append(f.path)
179
+ elif f.is_file():
180
+ if os.path.splitext(f.name)[1].lower() in exts:
181
+ files.append(f.path)
182
+ except Exception:
183
+ pass
184
+ except Exception:
185
+ pass
186
+
187
+ if recursive:
188
+ for path in list(subfolders):
189
+ sf, f = fast_scandir(path, exts, recursive=recursive)
190
+ subfolders.extend(sf)
191
+ files.extend(f) # type: ignore
192
+
193
+ return subfolders, files