File size: 1,240 Bytes
9b6e0aa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

import argparse
import json
import shutil
from pathlib import Path


MHB_ROOT = Path(__file__).resolve().parent.parent


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("test_dir", type=Path)
    args = parser.parse_args()

    test_dir = args.test_dir.expanduser().resolve()
    assert test_dir.is_dir(), f"Not found: {test_dir}"

    count = 0
    with (MHB_ROOT / "meta_data.jsonl").open("r", encoding="utf-8") as f:
        for line in f:
            if not line.strip():
                continue

            record = json.loads(line)
            if record["task_name"] != "DeepShip":
                continue

            category, event, recording, segment = record["id"].split("_")
            src = test_dir / category / event / f"{recording}.wav" / f"{segment}.wav"
            dst = MHB_ROOT / record["input_ts"]["path"]

            assert src.is_file(), f"Missing DeepShip segment: {src}"
            assert dst.name == f"{record['id']}.wav"

            dst.parent.mkdir(parents=True, exist_ok=True)
            shutil.copy2(src, dst)
            count += 1

    assert count == 527, f"Expected 527, got {count}"
    print(f"DeepShip: copied {count} files")


if __name__ == "__main__":
    main()