File size: 4,045 Bytes
7e6c03a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
from pathlib import Path
from concurrent.futures import ProcessPoolExecutor, as_completed
import os

import pandas as pd
import soundfile as sf
from tqdm import tqdm


# ============================================================
# Paths
# ============================================================

AUDIO_ROOT = Path("/home/debarpanb1/TREA_2.0/GISE/isolated_events")
CSV_PATH = Path("/home/debarpanb1/TREA_2.0/GISE/meta/gise_metadata.csv")

OUTPUT_PATH = Path("/home/debarpanb1/TREA_2.0/GISE/meta/gise_audio_format_check.csv")

NUM_WORKERS = min(16, os.cpu_count() or 4)


# ============================================================
# Worker
# ============================================================

def check_one(row_dict):
    relative_path = Path(row_dict["relative_path"])
    audio_path = AUDIO_ROOT / relative_path

    row_dict["audio_path"] = str(audio_path)
    row_dict["exists"] = audio_path.exists()
    row_dict["read_success"] = False
    row_dict["read_error"] = ""

    if not audio_path.exists():
        row_dict["read_error"] = "missing_audio_file"
        return row_dict

    try:
        info = sf.info(str(audio_path))

        row_dict["sample_rate"] = info.samplerate
        row_dict["channels"] = info.channels
        row_dict["frames"] = info.frames
        row_dict["duration"] = info.frames / info.samplerate
        row_dict["format"] = info.format
        row_dict["subtype"] = info.subtype
        row_dict["endian"] = info.endian
        row_dict["sections"] = info.sections
        row_dict["read_success"] = True

    except Exception as e:
        row_dict["read_error"] = repr(e)

    return row_dict


# ============================================================
# Main
# ============================================================

def main():
    df = pd.read_csv(CSV_PATH)
    records = df.to_dict("records")

    print(f"Checking {len(records)} GISE files with {NUM_WORKERS} workers...")

    results = []

    with ProcessPoolExecutor(max_workers=NUM_WORKERS) as executor:
        futures = [executor.submit(check_one, row) for row in records]

        for future in tqdm(as_completed(futures), total=len(futures)):
            results.append(future.result())

    out_df = pd.DataFrame(results)
    out_df.to_csv(OUTPUT_PATH, index=False)

    print("\nDone.")
    print(f"Saved detailed check to: {OUTPUT_PATH}")

    print("\nExists:")
    print(out_df["exists"].value_counts(dropna=False))

    print("\nRead success:")
    print(out_df["read_success"].value_counts(dropna=False))

    print("\nSample rates:")
    print(out_df["sample_rate"].value_counts(dropna=False).sort_index())

    print("\nChannels:")
    print(out_df["channels"].value_counts(dropna=False).sort_index())

    print("\nFormats:")
    print(out_df["format"].value_counts(dropna=False))

    print("\nSubtypes:")
    print(out_df["subtype"].value_counts(dropna=False))

    print("\nDuration summary:")
    print(out_df["duration"].describe())

    print("\nDuration filter counts:")
    print("duration < 0.5s:", (out_df["duration"] < 0.5).sum())
    print("0.5s <= duration <= 10s:", ((out_df["duration"] >= 0.5) & (out_df["duration"] <= 10.0)).sum())
    print("duration > 10s:", (out_df["duration"] > 10.0).sum())

    print("\nNon-22050 files:")
    non_22050 = out_df[out_df["sample_rate"] != 22050]
    print(len(non_22050))
    if len(non_22050) > 0:
        print(non_22050[["relative_path", "sample_rate", "channels", "format", "subtype", "duration"]].head(20))

    print("\nNon-PCM_16 files:")
    non_pcm16 = out_df[out_df["subtype"] != "PCM_16"]
    print(len(non_pcm16))
    if len(non_pcm16) > 0:
        print(non_pcm16[["relative_path", "sample_rate", "channels", "format", "subtype", "duration"]].head(20))

    print("\nNon-mono files:")
    non_mono = out_df[out_df["channels"] != 1]
    print(len(non_mono))
    if len(non_mono) > 0:
        print(non_mono[["relative_path", "sample_rate", "channels", "format", "subtype", "duration"]].head(20))


if __name__ == "__main__":
    main()