Alphawarheads commited on
Commit
067b479
·
verified ·
1 Parent(s): 7871518

Upload PC-Mix v1.2 dataset

Browse files
FILELIST.txt ADDED
The diff for this file is too large to render. See raw diff
 
Mixed_soundsV1.2/Mixed_soundsV1.2.tar.zst.part-000 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a7572623cfeeea97b2cce5c9d7ecca128e20efa0e99db1376a3626b8e82accae
3
+ size 2147483648
Mixed_soundsV1.2/Mixed_soundsV1.2.tar.zst.part-001 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1207da32c2acbd93e7e46e25c1620dbe188d18b6cc34086669392fccbfde95ce
3
+ size 2147483648
Mixed_soundsV1.2/Mixed_soundsV1.2.tar.zst.part-002 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:51218679737b515d7eb70f00b7a588cb3b4f312d6949e8ff8bea0c147793b4ac
3
+ size 2147483648
Mixed_soundsV1.2/Mixed_soundsV1.2.tar.zst.part-003 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9f58eeece10822ae252f3d0e01e67bb3ce2b451b463b4b043d1f707a4a38147c
3
+ size 2147483648
Mixed_soundsV1.2/Mixed_soundsV1.2.tar.zst.part-004 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ee42cfb76c2e639011080a84bb7a12839d47df51ae3f698abe4fd8c6966e5b21
3
+ size 2147483648
Mixed_soundsV1.2/Mixed_soundsV1.2.tar.zst.part-005 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6a9b185d6e3cd4de2678a7959e2ae63c5cb99662a6f21f2772f5013fcf0fdff2
3
+ size 2147483648
Mixed_soundsV1.2/Mixed_soundsV1.2.tar.zst.part-006 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f97c88a2299f7f4bdc84fead4ccb9780a624edea71ad3254cf1d8077607de6db
3
+ size 2147483648
Mixed_soundsV1.2/Mixed_soundsV1.2.tar.zst.part-007 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:334a2e4cf6b99576e23ea99162c2319639e6fe87f3fa8679ace230714484aca4
3
+ size 2147483648
Mixed_soundsV1.2/Mixed_soundsV1.2.tar.zst.part-008 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:83a9fa687c1eddf6f6a6d8a063dd43631029e264089fba884864a4ecc98f2c1a
3
+ size 2147483648
Mixed_soundsV1.2/Mixed_soundsV1.2.tar.zst.part-009 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dc56700012a8555111e6b2ed1f5a3e58ec18aacf1c40b8bc75b8b49c162048fd
3
+ size 2147483648
Mixed_soundsV1.2/Mixed_soundsV1.2.tar.zst.part-010 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3801fddbec1dcd11bed4206b1d68d54ed81820d182904f99b61ce8e1fef0c4a2
3
+ size 219526411
Partialspoof_background/Partialspoof_background.tar.zst.part-000 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5114f28b49ebb5386b4e77fac0c72b14cc633f3f070c5b60397c1fdbc8716d0c
3
+ size 2147483648
Partialspoof_background/Partialspoof_background.tar.zst.part-001 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bd4fe6003d09b8164b0655a4ffa82492e0b4f2112710751667a1933c6af3790c
3
+ size 2147483648
Partialspoof_background/Partialspoof_background.tar.zst.part-002 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:da4bb9a061cf18da50c6b00c5670ee9d3d3fb8ccedfdc413452955e6e77ad0ea
3
+ size 2147483648
Partialspoof_background/Partialspoof_background.tar.zst.part-003 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:95c708fa0adee20ba5e60e9a773dcbcba0c76511a67a55412e711ba193e7c85d
3
+ size 2147483648
Partialspoof_background/Partialspoof_background.tar.zst.part-004 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bc3c1dedfc3ea00634286d6381abd1056b5bd15964536dba4d6154a8d3f9b4da
3
+ size 262419374
README.md CHANGED
@@ -1,3 +1,347 @@
1
- ---
2
- license: cc-by-nc-4.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ pretty_name: "PC-Mix"
3
+ language:
4
+ - en
5
+ task_categories:
6
+ - audio-classification
7
+ tags:
8
+ - audio
9
+ - anti-spoofing
10
+ - partially-spoofed-audio
11
+ - environmental-sounds
12
+ license: other
13
+ ---
14
+
15
+ # PC-Mix Dataset
16
+
17
+ **Partial Spoof Dataset with Controlled Speech–Environmental Sounds Mixing**
18
+
19
+ PC-Mix pairs speech from **PartialSpoof v1.2** with a **self-curated partial-spoof environmental sounds pool** to create controlled speech–environment authenticity combinations. The **original** samples are collected from **VGGSound** and **SBCSAE**.
20
+
21
+ ## Resources
22
+
23
+ | Resource | Description | Link |
24
+ |---|---|---|
25
+ | GitHub | Code, protocols, and preprocessing scripts. | [Anonymous GitHub](https://anonymous.4open.science/r/PC-Mix-3AFE/README.md) |
26
+ | Paper | Dataset description and baselines. | PDF / arXiv (TBD) |
27
+ | Hugging Face | Dataset card and hosted files. | [HF Dataset](https://huggingface.co/datasets/Alphawarheads/PC-Mix) |
28
+ | Download | Direct access to the packaged dataset files. | [Download Files](https://huggingface.co/datasets/Alphawarheads/PC-Mix/tree/main) |
29
+
30
+ ## Download and Setup
31
+
32
+ PC-Mix is hosted on Hugging Face under `Alphawarheads/PC-Mix`. The dataset directories are compressed with `tar` and `zstd`, then split into fixed-size volumes for more convenient downloading. All archive parts belonging to the same directory must be downloaded before extraction.
33
+
34
+ ### Option 1: Download with Hugging Face CLI
35
+
36
+ ```bash
37
+ pip install -U "huggingface_hub[cli]"
38
+
39
+ huggingface-cli download Alphawarheads/PC-Mix \
40
+ --repo-type dataset \
41
+ --local-dir ./PC-Mix
42
+ ```
43
+
44
+ ### Option 2: Clone with Git LFS
45
+
46
+ ```bash
47
+ git lfs install
48
+
49
+ git clone https://huggingface.co/datasets/Alphawarheads/PC-Mix
50
+ ```
51
+
52
+ ### Option 3: Access from Python
53
+
54
+ ```python
55
+ from huggingface_hub import snapshot_download
56
+
57
+ snapshot_download(
58
+ repo_id="Alphawarheads/PC-Mix",
59
+ repo_type="dataset",
60
+ local_dir="./PC-Mix",
61
+ )
62
+ ```
63
+
64
+ ### Install the extraction dependency
65
+
66
+ The archive volumes use Zstandard compression.
67
+
68
+ Using Conda:
69
+
70
+ ```bash
71
+ conda install -c conda-forge zstd
72
+ ```
73
+
74
+ Using Ubuntu/Debian:
75
+
76
+ ```bash
77
+ sudo apt install zstd
78
+ ```
79
+
80
+ ## Packaged File Structure
81
+
82
+ The files hosted on Hugging Face are organized as follows:
83
+
84
+ ```text
85
+ PC-Mix/
86
+ ├── README.md
87
+ ├── buildSBCori.py
88
+ ├── extract_orig_from_mixed_protocol.py
89
+ ├── FILELIST.txt
90
+ ├── SHA256SUMS
91
+
92
+ ├── Mixed_soundsV1.2/
93
+ │ ├── Mixed_soundsV1.2.tar.zst.part-000
94
+ │ ├── Mixed_soundsV1.2.tar.zst.part-001
95
+ │ ├── Mixed_soundsV1.2.tar.zst.part-002
96
+ │ └── ...
97
+
98
+ └── Partialspoof_background/
99
+ ├── Partialspoof_background.tar.zst.part-000
100
+ ├── Partialspoof_background.tar.zst.part-001
101
+ └── ...
102
+ ```
103
+
104
+ The split volumes preserve the original directory names and all internal relative paths. After extraction, the dataset returns to the directory structure described in [Dataset Structure](#dataset-structure).
105
+
106
+ ### Verify downloaded volumes
107
+
108
+ Run the checksum verification from the downloaded repository root:
109
+
110
+ ```bash
111
+ cd ./PC-Mix
112
+ sha256sum -c SHA256SUMS
113
+ ```
114
+
115
+ Every successfully downloaded volume should be reported as `OK`.
116
+
117
+ ## Extract the Split Archives
118
+
119
+ Create a destination directory:
120
+
121
+ ```bash
122
+ mkdir -p ./PC_Mix_extracted
123
+ ```
124
+
125
+ ### Extract `Mixed_soundsV1.2`
126
+
127
+ ```bash
128
+ cat ./PC-Mix/Mixed_soundsV1.2/Mixed_soundsV1.2.tar.zst.part-* \
129
+ | zstd -dc \
130
+ | tar -xf - -C ./PC_Mix_extracted
131
+ ```
132
+
133
+ ### Extract `Partialspoof_background`
134
+
135
+ ```bash
136
+ cat ./PC-Mix/Partialspoof_background/Partialspoof_background.tar.zst.part-* \
137
+ | zstd -dc \
138
+ | tar -xf - -C ./PC_Mix_extracted
139
+ ```
140
+
141
+ After extraction:
142
+
143
+ ```text
144
+ PC_Mix_extracted/
145
+ ├── Mixed_soundsV1.2/
146
+ └── Partialspoof_background/
147
+ ```
148
+
149
+ Do not rename, individually decompress, or extract the `.part-*` files. They are consecutive parts of a single compressed archive and must be concatenated in numerical order.
150
+
151
+ ## Reconstruct the SBCSAE-Derived Original WAV Files
152
+
153
+ Due to the **CC BY-ND 3.0 US** license of SBCSAE, SBCSAE-derived cropped audio is not directly redistributed in PC-Mix. The repository provides the protocols and preprocessing scripts required to reconstruct these files locally after obtaining the official SBCSAE WAV data.
154
+
155
+ The reconstruction workflow uses:
156
+
157
+ - `extract_orig_from_mixed_protocol.py`
158
+ - `buildSBCori.py`
159
+ - the extracted `Mixed_soundsV1.2` directory
160
+ - the official SBCSAE `WAV` directory
161
+
162
+ ### 1. Remove SBCSAE-derived original files before redistribution
163
+
164
+ This command identifies SBCSAE-derived original entries through the mixed-data protocols and deletes their corresponding `train_orig_*` or `eval_orig_*` WAV files.
165
+
166
+ ```bash
167
+ python extract_orig_from_mixed_protocol.py \
168
+ --mixed_sounds_dir /dkucc/home/zz324/Audiodata/PC_Mix/Mixed_soundsV1.2 \
169
+ --delete
170
+ ```
171
+
172
+ This step is primarily used when preparing a redistributable release. Users downloading the public PC-Mix package normally receive a version in which these restricted files have already been removed.
173
+
174
+ ### 2. Reconstruct the omitted WAV files locally
175
+
176
+ After downloading the official SBCSAE audio and placing its WAV files under a local `WAV` directory, run:
177
+
178
+ ```bash
179
+ python buildSBCori.py \
180
+ --input_dir /dkucc/home/zz324/Audiodata/WAV \
181
+ --mixed_sounds_dir /dkucc/home/zz324/Audiodata/PC_Mix/Mixed_soundsV1.2 \
182
+ --protocol_ref /dkucc/home/zz324/Audiodata/PC_Mix/Mixed_soundsV1.2 \
183
+ --overwrite
184
+ ```
185
+
186
+ Arguments:
187
+
188
+ - `--input_dir`: directory containing the officially obtained SBCSAE WAV files.
189
+ - `--mixed_sounds_dir`: extracted `Mixed_soundsV1.2` directory in which the reconstructed original files will be written.
190
+ - `--protocol_ref`: directory containing the train and evaluation protocols used to locate the required SBCSAE source segments.
191
+ - `--overwrite`: regenerate target files even when files with the same names already exist.
192
+
193
+ The script reconstructs the omitted SBCSAE-derived original clips while preserving the expected PC-Mix file names and directory layout.
194
+
195
+ ## Audio Class Description
196
+
197
+ PC-Mix provides both utterance-level and frame-level annotations.
198
+
199
+ At the utterance level, each sample is assigned to one of five classes: one class for original real-world recordings and four classes for constructed mixtures with different speech/environmental-sound authenticity combinations.
200
+
201
+ At the frame level, PC-Mix focuses on constructed mixtures only. Each frame is assigned to one of four classes based on whether the speech component, the environmental-sound component, or both components are spoofed at that time.
202
+
203
+ ### Utterance-Level Classes
204
+
205
+ | Class | Name | Speech | Environmental Sounds | Description |
206
+ |---:|---|---|---|---|
207
+ | 0 | Original | — | — | A naturally recorded audio clip containing speech and environmental sounds, without artificial speech–environment mixing. |
208
+ | 1 | Bona fide + Bona fide | Bona fide | Bona fide | A constructed mixture where both the speech component and the environmental-sound component are bona fide. |
209
+ | 2 | Spoofed + Bona fide | Spoofed | Bona fide | A constructed mixture containing partially spoofed speech while the environmental-sound component remains bona fide. |
210
+ | 3 | Bona fide + Spoofed | Bona fide | Spoofed | A constructed mixture containing bona fide speech with partially spoofed environmental sounds. |
211
+ | 4 | Spoofed + Spoofed | Spoofed | Spoofed | A constructed mixture where both speech and environmental sounds contain partially spoofed regions. |
212
+
213
+ ### Frame-Level Classes
214
+
215
+ | Class | Name | Speech | Environmental Sounds | Description |
216
+ |---:|---|---|---|---|
217
+ | 0 | Bona fide frame | Bona fide | Bona fide | Neither component is spoofed in this frame. |
218
+ | 1 | Speech-spoofed frame | Spoofed | Bona fide | The local spoofing occurs in the speech component only. |
219
+ | 2 | Environmental-sound-spoofed frame | Bona fide | Spoofed | The local spoofing occurs in the environmental-sound component only. |
220
+ | 3 | Both-spoofed frame | Spoofed | Spoofed | Both speech and environmental sounds are spoofed in this frame. |
221
+
222
+ ## Dataset Structure
223
+
224
+ After the split archives have been extracted and the omitted SBCSAE-derived original clips have been reconstructed, the dataset follows this structure:
225
+
226
+ ```text
227
+ PC_Mix
228
+ ├── README.md
229
+
230
+ ├── Mixed_soundsV1.2 # mixed speech + environmental sounds audio
231
+ │ │
232
+ │ ├── train # training split
233
+ │ │ ├── protocol.txt # mapping from mixed audio to source speech/environmental sounds
234
+ │ │ ├── wav # mixed audio files, e.g., train_mix_0000000.wav
235
+ │ │ └── labels # NumPy label files
236
+ │ │ ├── speech # speech-component segment labels
237
+ │ │ ├── env # environmental-sounds component segment labels
238
+ │ │ ├── mix # mixture-level segment labels
239
+ │ │ └── original_vs_others_seglab # original-vs-non-original segment labels
240
+ │ │
241
+ │ ├── eval # evaluation split
242
+ │ │ ├── protocol.txt # mapping from mixed audio to source speech/environmental sounds
243
+ │ │ ├── wav # mixed audio files, e.g., eval_E0_mix_0000006.wav
244
+ │ │ └── labels # NumPy label files
245
+ │ │ ├── speech
246
+ │ │ ├── env
247
+ │ │ ├── mix
248
+ │ │ └── original_vs_others_seglab
249
+ │ │
250
+ │ ├── label_PartialSpoof_train # text-format PartialSpoof-style labels for training
251
+ │ │ ├── wav-train.scp
252
+ │ │ ├── original_vs_others_utt_labels.txt
253
+ │ │ ├── speech # train_protocol_*.txt
254
+ │ │ ├── env # train_protocol_*.txt
255
+ │ │ ├── mix # train_protocol_*.txt
256
+ │ │ └── original_vs_others_seglab # train_protocol_*.txt
257
+ │ │
258
+ │ └── label_PartialSpoof_eval # text-format PartialSpoof-style labels for evaluation
259
+ │ ├── wav-eval.scp
260
+ │ ├── original_vs_others_utt_labels.txt
261
+ │ ├── speech # eval_protocol_*.txt
262
+ │ ├── env # eval_protocol_*.txt
263
+ │ ├── mix # eval_protocol_*.txt
264
+ │ └── original_vs_others_seglab # eval_protocol_*.txt
265
+
266
+ └── Partialspoof_background # source environmental sounds data
267
+
268
+ ├── train # training environmental sounds split
269
+ │ ├── protocol.txt # environmental sounds audio protocol
270
+ │ ├── wav # environmental sounds audio files
271
+ │ └── labels # segment labels in .npy/.txt formats
272
+
273
+ ├── eval # evaluation environmental sounds split
274
+ │ ├── protocol.txt # environmental sounds audio protocol
275
+ │ ├── wav # environmental sounds audio files
276
+ │ └── labels # segment labels in .npy/.txt formats
277
+
278
+ ├── label_PartialSpoof_train # text-format environmental sounds labels for training
279
+ │ └── train_protocol_*.txt
280
+
281
+ └── label_PartialSpoof_eval # text-format environmental sounds labels for evaluation
282
+ └── eval_protocol_*.txt
283
+ ```
284
+
285
+ ## Audio Source
286
+
287
+ | Component | Source | Description |
288
+ |---|---|---|
289
+ | Speech | PartialSpoof v1.2 | Speech samples with partially spoofed speech annotations. |
290
+ | Environmental Sounds | Self-curated partial-spoof environmental sounds pool | Environmental sounds with controlled bona fide/spoofed component labels. |
291
+ | Original | VGGSound and SBCSAE | Original recordings without artificial speech–environment mixing. |
292
+
293
+ ## Data Splits
294
+
295
+ ### Training Set
296
+
297
+ | Split | Mixed Samples | Original Samples | Environmental Sounds Source | Event Source | Fusion Method |
298
+ |---|---:|---:|---|---|---|
299
+ | Train | 25,380 | 12,155 | SONYC | 60% AudioLDM2; 40% UrbanSound8K (0–1 s) | Ducking Overlay |
300
+
301
+ ### Evaluation Sets
302
+
303
+ | Subset | Mixed | Original | Environmental Sounds | Event | Fusion |
304
+ |---|---:|---:|---|---|---|
305
+ | E0 Baseline | 17,812 | 17,809 | SONYC | 60% AudioLDM2; 40% FSD50K (0–1 s) | Ducking Overlay |
306
+ | E1 Generator OOD | 14,248 | — | SONYC | AudioGen | Ducking Overlay |
307
+ | E2 Fusion OOD | 14,248 | — | SONYC | AudioLDM2 | Energy Matching + Crossfade (20–80 ms) |
308
+ | E3 Environmental Sounds OOD | 17,809 | — | DEMAND | AudioLDM2 | Ducking Overlay |
309
+ | E4 Noise OOD | 7,125 | — | WHAM Noise | AudioLDM2 | Ducking Overlay |
310
+
311
+ ## Metadata
312
+
313
+ Each mixed sample is associated with a protocol entry that records its mixed-audio ID, speech source, environmental sounds source, mixing duration, SNR, gain/scaling information, and offset information.
314
+
315
+ Example:
316
+
317
+ ```text
318
+ train_mix_0000000 mix CON_T_0000000.wav train_29_006663_s2.wav 1.000 1.400 snr_db=8.000 bg_scale=0.425705 offset_sec=0.909625 offset_samp=14554
319
+ ```
320
+
321
+ ## Citation
322
+
323
+ <!-- Citation information will be added after publication. -->
324
+
325
+ ## License 🔐
326
+
327
+ PC-Mix is released for non-commercial research purposes. Part of this dataset is a derived dataset constructed by combining, mixing, cropping, and generating audio samples from multiple publicly available datasets and audio generation models. Users must comply with the original licenses of all upstream datasets and models.
328
+
329
+ - The [PartialSpoof](https://zenodo.org/records/5112031), [VGGSound](https://www.robots.ox.ac.uk/~vgg/data/vggsound/), and [SONYC-UST](https://zenodo.org/records/3966543) datasets are released under the CC BY 4.0 license.
330
+
331
+ - The [UrbanSound8K](https://zenodo.org/records/1203745) and [WHAM!](https://wham.whisper.ai/) noise data are released under the CC BY-NC 4.0 license.
332
+
333
+ - The [FSD50K](https://zenodo.org/records/4060432) dataset contains audio clips under multiple Creative Commons licenses, including CC0, CC BY, CC BY-NC, and CC Sampling+. Users should follow the per-clip license metadata provided by FSD50K.
334
+
335
+ - The [DEMAND](https://zenodo.org/records/1227121) dataset is released under the CC BY-SA 3.0 license.
336
+
337
+ - The synthetic environmental event sounds generated by [AudioLDM2](https://huggingface.co/cvssp/audioldm2) are produced using model weights released under the CC BY-NC-SA 4.0 license.
338
+
339
+ - The synthetic environmental event sounds generated by [AudioGen](https://huggingface.co/facebook/audiogen-medium) are produced using model weights released under the CC BY-NC 4.0 license.
340
+
341
+ - The [SBCSAE / Santa Barbara Corpus of Spoken American English](https://www.openslr.org/155/) is released under the CC BY-ND 3.0 US license. Due to the NoDerivatives condition, SBCSAE-derived audio clips are not directly redistributed in PC-Mix. We only provide the official download link, segment-level metadata, and preprocessing scripts so that users who have obtained SBCSAE from the official source can reproduce this subset locally.
342
+
343
+ > **Important:** PC-Mix does not override the licenses of the original datasets or models. By using PC-Mix, users agree to comply with all upstream license terms.
344
+
345
+ ## Contact Information
346
+
347
+ <!-- Contact information will be added after the anonymous review period. -->
SHA256SUMS ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ a7572623cfeeea97b2cce5c9d7ecca128e20efa0e99db1376a3626b8e82accae ./Mixed_soundsV1.2/Mixed_soundsV1.2.tar.zst.part-000
2
+ 1207da32c2acbd93e7e46e25c1620dbe188d18b6cc34086669392fccbfde95ce ./Mixed_soundsV1.2/Mixed_soundsV1.2.tar.zst.part-001
3
+ 51218679737b515d7eb70f00b7a588cb3b4f312d6949e8ff8bea0c147793b4ac ./Mixed_soundsV1.2/Mixed_soundsV1.2.tar.zst.part-002
4
+ 9f58eeece10822ae252f3d0e01e67bb3ce2b451b463b4b043d1f707a4a38147c ./Mixed_soundsV1.2/Mixed_soundsV1.2.tar.zst.part-003
5
+ ee42cfb76c2e639011080a84bb7a12839d47df51ae3f698abe4fd8c6966e5b21 ./Mixed_soundsV1.2/Mixed_soundsV1.2.tar.zst.part-004
6
+ 6a9b185d6e3cd4de2678a7959e2ae63c5cb99662a6f21f2772f5013fcf0fdff2 ./Mixed_soundsV1.2/Mixed_soundsV1.2.tar.zst.part-005
7
+ f97c88a2299f7f4bdc84fead4ccb9780a624edea71ad3254cf1d8077607de6db ./Mixed_soundsV1.2/Mixed_soundsV1.2.tar.zst.part-006
8
+ 334a2e4cf6b99576e23ea99162c2319639e6fe87f3fa8679ace230714484aca4 ./Mixed_soundsV1.2/Mixed_soundsV1.2.tar.zst.part-007
9
+ 83a9fa687c1eddf6f6a6d8a063dd43631029e264089fba884864a4ecc98f2c1a ./Mixed_soundsV1.2/Mixed_soundsV1.2.tar.zst.part-008
10
+ dc56700012a8555111e6b2ed1f5a3e58ec18aacf1c40b8bc75b8b49c162048fd ./Mixed_soundsV1.2/Mixed_soundsV1.2.tar.zst.part-009
11
+ 3801fddbec1dcd11bed4206b1d68d54ed81820d182904f99b61ce8e1fef0c4a2 ./Mixed_soundsV1.2/Mixed_soundsV1.2.tar.zst.part-010
12
+ 5114f28b49ebb5386b4e77fac0c72b14cc633f3f070c5b60397c1fdbc8716d0c ./Partialspoof_background/Partialspoof_background.tar.zst.part-000
13
+ bd4fe6003d09b8164b0655a4ffa82492e0b4f2112710751667a1933c6af3790c ./Partialspoof_background/Partialspoof_background.tar.zst.part-001
14
+ da4bb9a061cf18da50c6b00c5670ee9d3d3fb8ccedfdc413452955e6e77ad0ea ./Partialspoof_background/Partialspoof_background.tar.zst.part-002
15
+ 95c708fa0adee20ba5e60e9a773dcbcba0c76511a67a55412e711ba193e7c85d ./Partialspoof_background/Partialspoof_background.tar.zst.part-003
16
+ bc3c1dedfc3ea00634286d6381abd1056b5bd15964536dba4d6154a8d3f9b4da ./Partialspoof_background/Partialspoof_background.tar.zst.part-004
buildSBCori.py ADDED
@@ -0,0 +1,492 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+
4
+ import argparse
5
+ import math
6
+ import re
7
+ from pathlib import Path
8
+ from dataclasses import dataclass
9
+ from typing import Dict, List, Optional, Tuple
10
+ from concurrent.futures import ThreadPoolExecutor, as_completed
11
+
12
+ import numpy as np
13
+ import soundfile as sf
14
+
15
+
16
+ AUDIO_EXTS = {".wav", ".flac", ".mp3", ".ogg", ".m4a"}
17
+
18
+ BGCLIP_RE = re.compile(
19
+ r"(?P<sbc>SBC\d+)_bgclip_"
20
+ r"(?P<start>\d+(?:\.\d+)?)_"
21
+ r"(?P<end>\d+(?:\.\d+)?)_"
22
+ r"score(?P<score>[-+]?\d+(?:\.\d+)?)"
23
+ )
24
+
25
+ SBC_RE = re.compile(r"SBC\d+")
26
+
27
+
28
+ @dataclass
29
+ class Task:
30
+ split: str
31
+ target_id: str
32
+ out_name: str
33
+ sbc_id: str
34
+ start_sec: float
35
+ end_sec: float
36
+ ref_token: str
37
+
38
+
39
+ def ensure_dir(p: Path) -> None:
40
+ p.mkdir(parents=True, exist_ok=True)
41
+
42
+
43
+ def load_audio(path: Path) -> Tuple[np.ndarray, int]:
44
+ x, sr = sf.read(str(path), always_2d=False)
45
+ if x.ndim == 2:
46
+ x = x.mean(axis=1)
47
+ return x.astype(np.float32), int(sr)
48
+
49
+
50
+ def save_audio(path: Path, x: np.ndarray, sr: int) -> None:
51
+ ensure_dir(path.parent)
52
+ x = np.asarray(x, dtype=np.float32)
53
+ sf.write(str(path), x, sr)
54
+
55
+
56
+ def resample_audio(x: np.ndarray, orig_sr: int, target_sr: int) -> np.ndarray:
57
+ if orig_sr == target_sr:
58
+ return x.astype(np.float32)
59
+
60
+ try:
61
+ from scipy.signal import resample_poly
62
+
63
+ g = math.gcd(orig_sr, target_sr)
64
+ up = target_sr // g
65
+ down = orig_sr // g
66
+ y = resample_poly(x, up, down)
67
+ return y.astype(np.float32)
68
+
69
+ except Exception:
70
+ new_len = max(1, int(round(len(x) * float(target_sr) / float(orig_sr))))
71
+ old_pos = np.arange(len(x), dtype=np.float64)
72
+ new_pos = np.linspace(0, len(x) - 1, new_len, dtype=np.float64)
73
+ y = np.interp(new_pos, old_pos, x)
74
+ return y.astype(np.float32)
75
+
76
+
77
+ def apply_fade(x: np.ndarray, sr: int, fade_sec: float) -> np.ndarray:
78
+ if fade_sec <= 0 or len(x) == 0:
79
+ return x
80
+
81
+ n = int(round(fade_sec * sr))
82
+ n = min(n, len(x) // 2)
83
+
84
+ if n <= 0:
85
+ return x
86
+
87
+ y = x.copy()
88
+ y[:n] *= np.linspace(0.0, 1.0, n, dtype=np.float32)
89
+ y[-n:] *= np.linspace(1.0, 0.0, n, dtype=np.float32)
90
+ return y
91
+
92
+
93
+ def normalize_out_name(target_id: str) -> str:
94
+ name = Path(target_id.strip().strip("'\"")).name
95
+ if Path(name).suffix.lower() not in AUDIO_EXTS:
96
+ name += ".wav"
97
+ else:
98
+ name = Path(name).stem + ".wav"
99
+ return name
100
+
101
+
102
+ def infer_split_from_path(p: Path) -> Optional[str]:
103
+ parts = [x.lower() for x in p.parts]
104
+ if "train" in parts:
105
+ return "train"
106
+ if "eval" in parts:
107
+ return "eval"
108
+ return None
109
+
110
+
111
+ def resolve_reference_protocols(reference: Path) -> Dict[str, Path]:
112
+ reference = reference.resolve()
113
+ protocols = {}
114
+
115
+ if reference.is_file():
116
+ split = infer_split_from_path(reference)
117
+ if split is None:
118
+ raise ValueError(
119
+ "Cannot infer split from reference protocol path. "
120
+ "Please put it under train/ or eval/: %s" % reference
121
+ )
122
+ protocols[split] = reference
123
+ return protocols
124
+
125
+ candidates = {
126
+ "train": [
127
+ reference / "train" / "protocol.txt",
128
+ reference / "train_protocol.txt",
129
+ reference / "train.txt",
130
+ ],
131
+ "eval": [
132
+ reference / "eval" / "protocol.txt",
133
+ reference / "eval_protocol.txt",
134
+ reference / "eval.txt",
135
+ ],
136
+ }
137
+
138
+ for split in ["train", "eval"]:
139
+ for p in candidates[split]:
140
+ if p.exists():
141
+ protocols[split] = p
142
+ break
143
+
144
+ if not protocols:
145
+ raise FileNotFoundError(
146
+ "Cannot find train/eval protocol under reference path: %s" % reference
147
+ )
148
+
149
+ return protocols
150
+
151
+
152
+ def parse_reference_protocol(protocol_path: Path, default_split: str) -> List[Task]:
153
+ """
154
+ Reference protocol example:
155
+
156
+ train_orig_0011153 orig train_05705_SBC036_bgclip_1211.00_1215.00_score19.3563.wav
157
+
158
+ 第一列: 输出名 train_orig_0011153.wav
159
+ 第二列: 必须是 orig
160
+ 第三列或整行: 提供 SBCxxx + start/end
161
+ """
162
+ tasks = []
163
+
164
+ with open(protocol_path, "r", encoding="utf-8", errors="ignore") as f:
165
+ for line_no, line in enumerate(f, 1):
166
+ line = line.strip()
167
+
168
+ if not line or line.startswith("#"):
169
+ continue
170
+
171
+ parts = line.split()
172
+ if len(parts) < 3:
173
+ continue
174
+
175
+ lower = [x.lower() for x in parts]
176
+ if "utt_id" in lower or "filename" in lower or "source_id" in lower:
177
+ continue
178
+
179
+ target_id = parts[0].strip()
180
+ label = parts[1].lower().strip()
181
+
182
+ if label != "orig":
183
+ continue
184
+
185
+ if target_id.startswith("train_"):
186
+ split = "train"
187
+ elif target_id.startswith("eval_"):
188
+ split = "eval"
189
+ else:
190
+ split = default_split
191
+
192
+ match = None
193
+ ref_token = ""
194
+
195
+ for item in parts[2:]:
196
+ m = BGCLIP_RE.search(item)
197
+ if m:
198
+ match = m
199
+ ref_token = item
200
+ break
201
+
202
+ if match is None:
203
+ m = BGCLIP_RE.search(line)
204
+ if m:
205
+ match = m
206
+ ref_token = line
207
+
208
+ if match is None:
209
+ continue
210
+
211
+ sbc_id = match.group("sbc")
212
+ start_sec = float(match.group("start"))
213
+ end_sec = float(match.group("end"))
214
+
215
+ if end_sec <= start_sec:
216
+ continue
217
+
218
+ tasks.append(
219
+ Task(
220
+ split=split,
221
+ target_id=target_id,
222
+ out_name=normalize_out_name(target_id),
223
+ sbc_id=sbc_id,
224
+ start_sec=start_sec,
225
+ end_sec=end_sec,
226
+ ref_token=ref_token,
227
+ )
228
+ )
229
+
230
+ return tasks
231
+
232
+
233
+ def build_source_index(input_dir: Path) -> Dict[str, List[Path]]:
234
+ """
235
+ Index raw SBC audio by SBC id.
236
+
237
+ Examples:
238
+ SBC036.wav -> SBC036
239
+ xxx_SBC036_yyy.wav -> SBC036
240
+ """
241
+ index = {}
242
+
243
+ for p in sorted(input_dir.rglob("*")):
244
+ if not p.is_file() or p.suffix.lower() not in AUDIO_EXTS:
245
+ continue
246
+
247
+ ids = SBC_RE.findall(p.stem)
248
+ for sbc_id in ids:
249
+ index.setdefault(sbc_id, []).append(p)
250
+
251
+ return index
252
+
253
+
254
+ def choose_source(sbc_id: str, source_index: Dict[str, List[Path]]) -> Optional[Path]:
255
+ candidates = source_index.get(sbc_id, [])
256
+
257
+ if not candidates:
258
+ return None
259
+
260
+ exact = [p for p in candidates if p.stem == sbc_id]
261
+ if len(exact) == 1:
262
+ return exact[0]
263
+
264
+ if len(candidates) == 1:
265
+ return candidates[0]
266
+
267
+ return None
268
+
269
+
270
+ def deduplicate_tasks(tasks: List[Task]) -> Tuple[List[Task], List[Task]]:
271
+ seen = set()
272
+ kept = []
273
+ dropped = []
274
+
275
+ for t in tasks:
276
+ key = (t.split, t.out_name)
277
+ if key in seen:
278
+ dropped.append(t)
279
+ continue
280
+ seen.add(key)
281
+ kept.append(t)
282
+
283
+ return kept, dropped
284
+
285
+
286
+ def process_source_group(
287
+ sbc_id: str,
288
+ tasks: List[Task],
289
+ source_index: Dict[str, List[Path]],
290
+ mixed_sounds_dir: Path,
291
+ target_sr: int,
292
+ fade_sec: float,
293
+ overwrite: bool,
294
+ ):
295
+ source_path = choose_source(sbc_id, source_index)
296
+
297
+ if source_path is None:
298
+ candidates = source_index.get(sbc_id, [])
299
+ if not candidates:
300
+ return 0, 0, ["source not found: %s" % sbc_id]
301
+
302
+ example = " | ".join(str(p) for p in candidates[:8])
303
+ return 0, 0, ["ambiguous source for %s: %s" % (sbc_id, example)]
304
+
305
+ try:
306
+ x, sr = load_audio(source_path)
307
+ except Exception as e:
308
+ return 0, 0, ["failed to load %s: %s" % (source_path, e)]
309
+
310
+ made = 0
311
+ skipped = 0
312
+ failed = []
313
+
314
+ for task in tasks:
315
+ out_dir = mixed_sounds_dir / task.split / "wav"
316
+ ensure_dir(out_dir)
317
+
318
+ out_path = out_dir / task.out_name
319
+
320
+ if out_path.exists() and not overwrite:
321
+ skipped += 1
322
+ continue
323
+
324
+ start = int(round(task.start_sec * sr))
325
+ end = int(round(task.end_sec * sr))
326
+
327
+ if start < 0 or end > len(x) or end <= start:
328
+ duration = len(x) / float(sr)
329
+ failed.append(
330
+ "bad segment: %s %.2f-%.2f, source duration %.2f sec, target %s"
331
+ % (task.sbc_id, task.start_sec, task.end_sec, duration, task.out_name)
332
+ )
333
+ continue
334
+
335
+ try:
336
+ clip = x[start:end]
337
+ clip = resample_audio(clip, sr, target_sr)
338
+ clip = apply_fade(clip, target_sr, fade_sec)
339
+ save_audio(out_path, clip, target_sr)
340
+ made += 1
341
+ except Exception as e:
342
+ failed.append("failed task %s from %s: %s" % (task.out_name, source_path, e))
343
+
344
+ return made, skipped, failed
345
+
346
+
347
+ def main():
348
+ parser = argparse.ArgumentParser(
349
+ description=(
350
+ "Cut raw SBC audio by reference Mixed_sounds protocol, "
351
+ "rename to train_orig/eval_orig ids, resample to 16k, "
352
+ "and inject wav files into target Mixed_sounds."
353
+ )
354
+ )
355
+
356
+ parser.add_argument(
357
+ "--input_dir",
358
+ type=str,
359
+ required=True,
360
+ help="Raw SBC audio root, e.g. /dkucc/home/zz324/Audiodata/WAV",
361
+ )
362
+ parser.add_argument(
363
+ "--mixed_sounds_dir",
364
+ type=str,
365
+ required=True,
366
+ help="Target Mixed_sounds directory to inject audio into.",
367
+ )
368
+ parser.add_argument(
369
+ "--reference",
370
+ type=str,
371
+ required=True,
372
+ help=(
373
+ "Reference protocol source. "
374
+ "Can be Mixed_soundsV1.2 root or a specific train/eval/protocol.txt."
375
+ ),
376
+ )
377
+
378
+ parser.add_argument("--target_sr", type=int, default=16000)
379
+ parser.add_argument("--fade_sec", type=float, default=0.5)
380
+ parser.add_argument("--num_workers", type=int, default=32)
381
+ parser.add_argument("--overwrite", action="store_true")
382
+
383
+ args = parser.parse_args()
384
+
385
+ input_dir = Path(args.input_dir).resolve()
386
+ mixed_sounds_dir = Path(args.mixed_sounds_dir).resolve()
387
+ reference = Path(args.reference).resolve()
388
+
389
+ ensure_dir(mixed_sounds_dir / "train" / "wav")
390
+ ensure_dir(mixed_sounds_dir / "eval" / "wav")
391
+
392
+ print("[INFO] input_dir :", input_dir)
393
+ print("[INFO] mixed_sounds_dir :", mixed_sounds_dir)
394
+ print("[INFO] reference :", reference)
395
+ print("[INFO] target_sr :", args.target_sr)
396
+ print("[INFO] fade_sec :", args.fade_sec)
397
+ print("[INFO] num_workers :", args.num_workers)
398
+ print("[INFO] overwrite :", args.overwrite)
399
+ print("[INFO] No new protocol will be generated.")
400
+ print("[INFO] Read reference protocol for BOTH renaming and cutting.")
401
+
402
+ protocols = resolve_reference_protocols(reference)
403
+
404
+ print("\n==================== Reference Protocols ====================")
405
+ for split, p in protocols.items():
406
+ print("[INFO] %s protocol: %s" % (split, p))
407
+
408
+ all_tasks = []
409
+
410
+ for split, protocol_path in protocols.items():
411
+ tasks = parse_reference_protocol(protocol_path, default_split=split)
412
+ all_tasks.extend(tasks)
413
+ print("[INFO] parsed %s tasks: %d" % (split, len(tasks)))
414
+
415
+ if not all_tasks:
416
+ print("[ERROR] No valid orig tasks found from reference protocol.")
417
+ return
418
+
419
+ all_tasks, dropped = deduplicate_tasks(all_tasks)
420
+
421
+ if dropped:
422
+ print("[WARN] duplicate output names in reference protocol:", len(dropped))
423
+ print("[WARN] duplicated tasks are skipped.")
424
+ for t in dropped[:20]:
425
+ print(" -", t.split, t.out_name, t.sbc_id, t.start_sec, t.end_sec)
426
+
427
+ print("\n==================== Source Index ====================")
428
+ source_index = build_source_index(input_dir)
429
+ print("[INFO] indexed SBC ids:", len(source_index))
430
+
431
+ grouped = {}
432
+ for task in all_tasks:
433
+ grouped.setdefault(task.sbc_id, []).append(task)
434
+
435
+ print("[INFO] task count :", len(all_tasks))
436
+ print("[INFO] source groups :", len(grouped))
437
+
438
+ total_made = 0
439
+ total_skipped = 0
440
+ all_failed = []
441
+
442
+ print("\n==================== Injecting Audio ====================")
443
+
444
+ with ThreadPoolExecutor(max_workers=args.num_workers) as ex:
445
+ futures = [
446
+ ex.submit(
447
+ process_source_group,
448
+ sbc_id,
449
+ tasks,
450
+ source_index,
451
+ mixed_sounds_dir,
452
+ args.target_sr,
453
+ args.fade_sec,
454
+ args.overwrite,
455
+ )
456
+ for sbc_id, tasks in grouped.items()
457
+ ]
458
+
459
+ for i, fut in enumerate(as_completed(futures), 1):
460
+ made, skipped, failed = fut.result()
461
+ total_made += made
462
+ total_skipped += skipped
463
+ all_failed.extend(failed)
464
+
465
+ if i % 10 == 0 or i == len(futures):
466
+ print(
467
+ "[INFO] processed groups %d/%d | injected=%d | skipped=%d | failed=%d"
468
+ % (i, len(futures), total_made, total_skipped, len(all_failed))
469
+ )
470
+
471
+ print("\n==================== Done ====================")
472
+ print("Reference tasks :", len(all_tasks))
473
+ print("Injected audio files :", total_made)
474
+ print("Skipped existing :", total_skipped)
475
+ print("Failed tasks :", len(all_failed))
476
+ print("Train wav dir :", mixed_sounds_dir / "train" / "wav")
477
+ print("Eval wav dir :", mixed_sounds_dir / "eval" / "wav")
478
+
479
+ if all_failed:
480
+ failed_path = mixed_sounds_dir / "inject_failed.txt"
481
+ with open(failed_path, "w", encoding="utf-8") as f:
482
+ for x in all_failed:
483
+ f.write(x + "\n")
484
+
485
+ print("[WARN] Failed details saved to:", failed_path)
486
+ print("\nFirst failed examples:")
487
+ for x in all_failed[:20]:
488
+ print(" -", x)
489
+
490
+
491
+ if __name__ == "__main__":
492
+ main()
extract_orig_from_mixed_protocol.py ADDED
@@ -0,0 +1,272 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+
4
+ import argparse
5
+ from pathlib import Path
6
+
7
+ AUDIO_EXTS = [".wav", ".flac", ".mp3", ".ogg", ".m4a"]
8
+
9
+
10
+ def is_audio_name(x: str) -> bool:
11
+ return Path(x).suffix.lower() in AUDIO_EXTS
12
+
13
+
14
+ def is_sbc_source(x: str) -> bool:
15
+ """
16
+ 第三列来源文件是否是 SBC 切片。
17
+ 例如:
18
+ train_02263_SBC023_bgclip_1123.00_1127.00_score54.7008.wav
19
+ """
20
+ name = Path(x).name
21
+ return "SBC" in name and is_audio_name(name)
22
+
23
+
24
+ def parse_protocol(protocol_path: Path):
25
+ """
26
+ 返回所有 label == orig 的行,并标记第三列是否是 SBC 来源。
27
+ 兼容格式:
28
+ train_orig_0007711 orig train_02263_SBC023_bgclip_1123.00_1127.00_score54.7008.wav
29
+ """
30
+ orig_rows = []
31
+
32
+ with open(protocol_path, "r", encoding="utf-8", errors="ignore") as f:
33
+ for line_no, line in enumerate(f, 1):
34
+ line = line.strip()
35
+
36
+ if not line or line.startswith("#"):
37
+ continue
38
+
39
+ parts = line.split()
40
+ if len(parts) < 2:
41
+ continue
42
+
43
+ utt_id = parts[0]
44
+ label = parts[1]
45
+
46
+ # 跳过表头
47
+ if utt_id.lower() in {"utt_id", "id"} or label.lower() == "label":
48
+ continue
49
+
50
+ if label != "orig":
51
+ continue
52
+
53
+ src = parts[2] if len(parts) >= 3 else ""
54
+
55
+ orig_rows.append({
56
+ "line_no": line_no,
57
+ "utt_id": utt_id,
58
+ "src": Path(src).name if src else "",
59
+ "is_sbc": is_sbc_source(src),
60
+ })
61
+
62
+ return orig_rows
63
+
64
+
65
+ def find_target_file(wav_dir: Path, utt_id: str):
66
+ """
67
+ 要删的是第一列 utt_id 对应的音频:
68
+ train_orig_0007711 -> train_orig_0007711.wav
69
+ """
70
+ for ext in AUDIO_EXTS:
71
+ p = wav_dir / f"{utt_id}{ext}"
72
+ if p.exists():
73
+ return p
74
+ return None
75
+
76
+
77
+ def process_split(mixed_dir: Path, split: str, do_delete: bool):
78
+ split_dir = mixed_dir / split
79
+ wav_dir = split_dir / "wav"
80
+ protocol_path = split_dir / "protocol.txt"
81
+
82
+ result = {
83
+ "split": split,
84
+ "total_orig_rows": 0,
85
+ "sbc_orig_rows": 0,
86
+ "non_sbc_orig_rows": 0,
87
+ "existing_delete_files": 0,
88
+ "missing_delete_files": 0,
89
+ "deleted_files": 0,
90
+ "delete_targets": [],
91
+ "missing_targets": [],
92
+ "non_sbc_orig": [],
93
+ }
94
+
95
+ if not protocol_path.exists():
96
+ print(f"[WARN] Missing protocol: {protocol_path}")
97
+ return result
98
+
99
+ if not wav_dir.exists():
100
+ print(f"[WARN] Missing wav dir: {wav_dir}")
101
+ return result
102
+
103
+ orig_rows = parse_protocol(protocol_path)
104
+
105
+ result["total_orig_rows"] = len(orig_rows)
106
+
107
+ for r in orig_rows:
108
+ if not r["is_sbc"]:
109
+ result["non_sbc_orig_rows"] += 1
110
+ result["non_sbc_orig"].append(r)
111
+ continue
112
+
113
+ result["sbc_orig_rows"] += 1
114
+
115
+ target = find_target_file(wav_dir, r["utt_id"])
116
+
117
+ if target is None:
118
+ result["missing_delete_files"] += 1
119
+ result["missing_targets"].append(r)
120
+ continue
121
+
122
+ result["existing_delete_files"] += 1
123
+ result["delete_targets"].append({
124
+ **r,
125
+ "target": target,
126
+ })
127
+
128
+ if do_delete:
129
+ target.unlink()
130
+ result["deleted_files"] += 1
131
+
132
+ return result
133
+
134
+
135
+ def write_reports(report_dir: Path, mixed_dir: Path, results):
136
+ report_dir.mkdir(parents=True, exist_ok=True)
137
+
138
+ summary_path = report_dir / "summary.txt"
139
+
140
+ with open(summary_path, "w", encoding="utf-8") as f:
141
+ f.write(
142
+ "split total_orig sbc_orig non_sbc_orig "
143
+ "existing_to_delete missing_to_delete deleted\n"
144
+ )
145
+
146
+ for r in results:
147
+ f.write(
148
+ f"{r['split']} "
149
+ f"{r['total_orig_rows']} "
150
+ f"{r['sbc_orig_rows']} "
151
+ f"{r['non_sbc_orig_rows']} "
152
+ f"{r['existing_delete_files']} "
153
+ f"{r['missing_delete_files']} "
154
+ f"{r['deleted_files']}\n"
155
+ )
156
+
157
+ f.write("\n")
158
+
159
+ f.write(
160
+ f"TOTAL "
161
+ f"{sum(r['total_orig_rows'] for r in results)} "
162
+ f"{sum(r['sbc_orig_rows'] for r in results)} "
163
+ f"{sum(r['non_sbc_orig_rows'] for r in results)} "
164
+ f"{sum(r['existing_delete_files'] for r in results)} "
165
+ f"{sum(r['missing_delete_files'] for r in results)} "
166
+ f"{sum(r['deleted_files'] for r in results)}\n"
167
+ )
168
+
169
+ for r in results:
170
+ split = r["split"]
171
+
172
+ with open(report_dir / f"{split}_delete_targets.txt", "w", encoding="utf-8") as f:
173
+ f.write("line_no utt_id src_sbc target_file\n")
174
+ for x in r["delete_targets"]:
175
+ rel = x["target"].relative_to(mixed_dir)
176
+ f.write(f"{x['line_no']} {x['utt_id']} {x['src']} {rel}\n")
177
+
178
+ with open(report_dir / f"{split}_missing_targets.txt", "w", encoding="utf-8") as f:
179
+ f.write("line_no utt_id src_sbc expected_file\n")
180
+ for x in r["missing_targets"]:
181
+ f.write(f"{x['line_no']} {x['utt_id']} {x['src']} {split}/wav/{x['utt_id']}.wav\n")
182
+
183
+ with open(report_dir / f"{split}_non_sbc_orig_kept.txt", "w", encoding="utf-8") as f:
184
+ f.write("line_no utt_id src\n")
185
+ for x in r["non_sbc_orig"]:
186
+ f.write(f"{x['line_no']} {x['utt_id']} {x['src']}\n")
187
+
188
+
189
+ def print_summary(results, do_delete: bool, report_dir: Path):
190
+ print("\n==================== Summary ====================")
191
+ print(f"Mode : {'DELETE' if do_delete else 'DRY-RUN'}")
192
+ print(f"Report dir : {report_dir}")
193
+
194
+ total_orig = 0
195
+ total_sbc = 0
196
+ total_non_sbc = 0
197
+ total_existing = 0
198
+ total_missing = 0
199
+ total_deleted = 0
200
+
201
+ for r in results:
202
+ total_orig += r["total_orig_rows"]
203
+ total_sbc += r["sbc_orig_rows"]
204
+ total_non_sbc += r["non_sbc_orig_rows"]
205
+ total_existing += r["existing_delete_files"]
206
+ total_missing += r["missing_delete_files"]
207
+ total_deleted += r["deleted_files"]
208
+
209
+ print(f"\n[{r['split']}]")
210
+ print(f" Total orig rows : {r['total_orig_rows']}")
211
+ print(f" SBC-corresponding orig rows : {r['sbc_orig_rows']}")
212
+ print(f" Non-SBC orig rows kept : {r['non_sbc_orig_rows']}")
213
+ print(f" Existing files to delete : {r['existing_delete_files']}")
214
+ print(f" Missing target files : {r['missing_delete_files']}")
215
+ print(f" Deleted files : {r['deleted_files']}")
216
+
217
+ print("\n[TOTAL]")
218
+ print(f" Total orig rows : {total_orig}")
219
+ print(f" SBC-corresponding orig rows : {total_sbc}")
220
+ print(f" Non-SBC orig rows kept : {total_non_sbc}")
221
+ print(f" Existing files to delete : {total_existing}")
222
+ print(f" Missing target files : {total_missing}")
223
+ print(f" Deleted files : {total_deleted}")
224
+
225
+ if total_orig > 0:
226
+ ratio = total_sbc / total_orig * 100
227
+ print(f" SBC-orig ratio : {ratio:.2f}%")
228
+
229
+ if not do_delete:
230
+ print("\n[DRY-RUN] 没有真正删除。确认 existing files to delete 数量正确后,加 --delete 再运行。")
231
+
232
+
233
+ def main():
234
+ parser = argparse.ArgumentParser(
235
+ description="Compare total orig rows with SBC-corresponding orig rows, then delete only those orig wavs."
236
+ )
237
+
238
+ parser.add_argument(
239
+ "--mixed_sounds_dir",
240
+ type=str,
241
+ required=True,
242
+ help="Path to Mixed_sounds directory.",
243
+ )
244
+
245
+ parser.add_argument(
246
+ "--delete",
247
+ action="store_true",
248
+ help="Actually delete files. Default is dry-run.",
249
+ )
250
+
251
+ args = parser.parse_args()
252
+
253
+ mixed_dir = Path(args.mixed_sounds_dir).resolve()
254
+ report_dir = mixed_dir / "delete_sbc_orig_compare_report"
255
+
256
+ results = []
257
+
258
+ for split in ["train", "eval"]:
259
+ results.append(
260
+ process_split(
261
+ mixed_dir=mixed_dir,
262
+ split=split,
263
+ do_delete=args.delete,
264
+ )
265
+ )
266
+
267
+ write_reports(report_dir, mixed_dir, results)
268
+ print_summary(results, args.delete, report_dir)
269
+
270
+
271
+ if __name__ == "__main__":
272
+ main()