Upload as_extract.py with huggingface_hub
Browse files- as_extract.py +6 -4
as_extract.py
CHANGED
|
@@ -20,7 +20,8 @@ rows = []
|
|
| 20 |
n_expl = n_veh = scanned = 0
|
| 21 |
ds = load_dataset("agkphysics/AudioSet", "full", streaming=True, token=os.environ["HF_TOKEN"])
|
| 22 |
for split in ("bal_train", "eval", "unbal_train"):
|
| 23 |
-
|
|
|
|
| 24 |
scanned += 1
|
| 25 |
if split == "unbal_train" and scanned > SCAN_CAP:
|
| 26 |
break
|
|
@@ -36,9 +37,10 @@ for split in ("bal_train", "eval", "unbal_train"):
|
|
| 36 |
continue
|
| 37 |
if cls == "vehicle_mechanical" and n_veh >= CAP_VEH:
|
| 38 |
continue
|
| 39 |
-
|
| 40 |
-
arr =
|
| 41 |
-
|
|
|
|
| 42 |
buf = io.BytesIO()
|
| 43 |
sf.write(buf, arr, sr, format="WAV", subtype="PCM_16")
|
| 44 |
rows.append({
|
|
|
|
| 20 |
n_expl = n_veh = scanned = 0
|
| 21 |
ds = load_dataset("agkphysics/AudioSet", "full", streaming=True, token=os.environ["HF_TOKEN"])
|
| 22 |
for split in ("bal_train", "eval", "unbal_train"):
|
| 23 |
+
sds = ds[split].cast_column("audio", Audio(decode=False)) # raw bytes; decode with soundfile
|
| 24 |
+
for ex in sds:
|
| 25 |
scanned += 1
|
| 26 |
if split == "unbal_train" and scanned > SCAN_CAP:
|
| 27 |
break
|
|
|
|
| 37 |
continue
|
| 38 |
if cls == "vehicle_mechanical" and n_veh >= CAP_VEH:
|
| 39 |
continue
|
| 40 |
+
raw = ex["audio"]["bytes"]
|
| 41 |
+
arr, sr = sf.read(io.BytesIO(raw), dtype="float32", always_2d=False)
|
| 42 |
+
if arr.ndim > 1:
|
| 43 |
+
arr = arr.mean(axis=1)
|
| 44 |
buf = io.BytesIO()
|
| 45 |
sf.write(buf, arr, sr, format="WAV", subtype="PCM_16")
|
| 46 |
rows.append({
|