qanastek commited on
Commit
4ac3e92
·
verified ·
1 Parent(s): 6e27e58

Upload 11 files

Browse files
README.md ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags:
3
+ - audio
4
+ configs:
5
+ - config_name: default
6
+ data_files:
7
+ - split: train
8
+ path: data/train-00000-of-00001.parquet
9
+ ---
10
+
11
+ # Background Noise Dataset
12
+
13
+ This dataset contains **3** audio recordings of **2** different background noise classes.
14
+
15
+ ## Dataset Statistics
16
+
17
+ - **Total Audio Files**: 3
18
+ - **Total Classes**: 2
19
+ - **Format**: WAV (converted to Parquet for Hugging Face Datasets)
20
+
21
+ ## Classes and Descriptions
22
+
23
+ The dataset covers the following background noises:
24
+
25
+ | Label | Description |
26
+ | :--- | :--- |
27
+ | `fan_noise` | Fan noise background |
28
+ | `white_noise` | White noise background |
29
+
30
+ ## Structure
31
+
32
+ The dataset is organized in a folder structure where each subdirectory corresponds to a class label.
33
+ A `metadata.csv` file provides the file paths, labels, and descriptions.
34
+
35
+ ### Columns
36
+
37
+ - `audio`: Path to the audio file.
38
+ - `label`: The category label of the background noise.
39
+ - `description`: A text description of the background noise.
40
+
41
+ ## Usage
42
+
43
+ ```python
44
+ from datasets import load_dataset
45
+
46
+ ds = load_dataset("sdialog/background")
47
+ ```
convert_to_parquet.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import csv
3
+ from datasets import Dataset, Audio, Features, Value, Version
4
+
5
+ # Point to the current directory
6
+ dataset_path = os.path.dirname(os.path.abspath(__file__))
7
+
8
+ # Dataset metadata
9
+ VERSION = Version("1.0.0")
10
+ DESCRIPTION = "Background noise dataset."
11
+ HOMEPAGE = "https://huggingface.co/datasets/sdialog/background"
12
+ LICENSE = "CC BY-NC-SA 4.0"
13
+
14
+ # Define features
15
+ features = Features({
16
+ "audio": Audio(sampling_rate=16000),
17
+ "file_path": Value("string"),
18
+ "label": Value("string"),
19
+ "description": Value("string"),
20
+ })
21
+
22
+
23
+ def dataset_generator():
24
+ csv_path = os.path.join(dataset_path, "metadata.csv")
25
+ if not os.path.exists(csv_path):
26
+ raise FileNotFoundError(
27
+ f"{csv_path} not found. Run create_metadata.py first."
28
+ )
29
+
30
+ with open(csv_path, "r", encoding="utf-8") as f:
31
+ reader = csv.DictReader(f)
32
+ for row in reader:
33
+ audio_path = row["audio"]
34
+ # Ensure the path is absolute for reading
35
+ # audio_path is relative to the dataset root
36
+ full_path = os.path.join(dataset_path, audio_path)
37
+
38
+ # Read audio bytes to ensure embedding
39
+ with open(full_path, "rb") as audio_file:
40
+ audio_bytes = audio_file.read()
41
+
42
+ yield {
43
+ "audio": {"path": None, "bytes": audio_bytes},
44
+ "file_path": audio_path,
45
+ "label": row["label"],
46
+ "description": row["description"]
47
+ }
48
+
49
+
50
+ print("Creating dataset from generator (embedding bytes)...")
51
+ ds = Dataset.from_generator(dataset_generator, features=features)
52
+
53
+ # Set dataset info
54
+ ds.info.version = VERSION
55
+ ds.info.description = DESCRIPTION
56
+ ds.info.homepage = HOMEPAGE
57
+ ds.info.license = LICENSE
58
+
59
+ print("Saving to Parquet...")
60
+ output_path = os.path.join(dataset_path, "data/train-00000-of-00001.parquet")
61
+ os.makedirs(os.path.dirname(output_path), exist_ok=True)
62
+ ds.to_parquet(output_path)
63
+
64
+ print(f"Saved to {output_path}")
create_metadata.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import csv
3
+
4
+ # Define paths
5
+ base_path = os.path.dirname(os.path.abspath(__file__))
6
+ # The audio folders are directly in the base path for this dataset
7
+ train_dir = base_path
8
+ tags_path = os.path.join(base_path, "tags_labels.csv")
9
+ output_csv = os.path.join(base_path, "metadata.csv")
10
+
11
+ # Load tags/descriptions
12
+ labels_desc = {}
13
+ if os.path.exists(tags_path):
14
+ with open(tags_path, 'r', encoding='utf-8') as file_tags:
15
+ for line in file_tags:
16
+ parts = line.strip().split(';')
17
+ if len(parts) >= 2:
18
+ tag_name = parts[0].strip()
19
+ tag_description = parts[1].strip()
20
+ labels_desc[tag_name] = tag_description
21
+ else:
22
+ print(f"Warning: {tags_path} not found.")
23
+
24
+ # Prepare CSV data
25
+ csv_data = []
26
+ header = ["audio", "label", "description"]
27
+
28
+ if os.path.exists(train_dir):
29
+ # Iterate over label directories
30
+ for label in sorted(os.listdir(train_dir)):
31
+ label_dir = os.path.join(train_dir, label)
32
+
33
+ # Skip hidden files, non-directories, and special folders/files
34
+ if not os.path.isdir(label_dir) or label.startswith('.'):
35
+ continue
36
+
37
+ # Only process directories that are likely audio labels (simple heuristic or check against tags)
38
+ # Here we just check if it's not the 'data' output folder or hidden
39
+ if label == "data":
40
+ continue
41
+
42
+ description = labels_desc.get(label, "XXX")
43
+
44
+ # Iterate over audio files in the label directory
45
+ for audio_file in sorted(os.listdir(label_dir)):
46
+ if audio_file.lower().endswith(('.wav', '.mp3', '.ogg', '.flac')):
47
+ # Create relative path: label/file.wav (relative to metadata.csv location)
48
+ relative_path = os.path.join(label, audio_file)
49
+
50
+ csv_data.append([relative_path, label, description])
51
+
52
+ # Write to CSV
53
+ with open(output_csv, "w", newline="", encoding="utf-8") as f:
54
+ writer = csv.writer(f)
55
+ writer.writerow(header)
56
+ writer.writerows(csv_data)
57
+
58
+ print(f"Successfully created {output_csv} with {len(csv_data)} entries.")
data/train-00000-of-00001.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a004d9643330d231dc5d9f33f68bd1231f1cab7389724fed1c475bb1fe712d5a
3
+ size 56822341
fan_noise/210098__yuval__room-big-fan.wav ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:91411e5b157cf23d925abac6bd38ee36c5701d3a4011a9a8f9d383c5ad223347
3
+ size 24617496
fan_noise/674563__klankbeeld__room-tone-fan-801am-220813_0497.wav ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c735017ce0aafc2c4b5fd3b13dc3de31f52b3b6caae36b429b87ca8e00bc9011
3
+ size 29840984
generate_data.sh ADDED
@@ -0,0 +1 @@
 
 
1
+ python create_metadata.py && python convert_to_parquet.py
metadata.csv ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ audio,label,description
2
+ fan_noise/210098__yuval__room-big-fan.wav,fan_noise,Fan noise background
3
+ fan_noise/674563__klankbeeld__room-tone-fan-801am-220813_0497.wav,fan_noise,Fan noise background
4
+ white_noise/white_zero_zero.wav,white_noise,White noise background
tags_labels.csv ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ fan_noise;Fan noise background
2
+ white_noise;White noise background
test_dataset.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datasets import load_dataset
2
+ import os
3
+
4
+ # Point to the parquet file generated
5
+ dataset_path = os.path.join(os.path.dirname(__file__), "data/train-00000-of-00001.parquet")
6
+
7
+ if not os.path.exists(dataset_path):
8
+ print(f"Dataset file not found at {dataset_path}")
9
+ print("Please run convert_to_parquet.py first.")
10
+ exit(1)
11
+
12
+ print(f"Loading background dataset from {dataset_path}...")
13
+ ds = load_dataset("parquet", data_files={"train": dataset_path}, split="train")
14
+
15
+ print("\nDataset Info:")
16
+ print(ds)
17
+
18
+ print("\nFeatures:")
19
+ print(ds.features)
20
+
21
+ print("\nFirst Example:")
22
+ item = ds[0]
23
+ print(item)
24
+
25
+ print("\nChecking file_path:")
26
+ print(f"File Path: {item['file_path']}")
white_noise/white_zero_zero.wav ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4cb253ff26c63417a0fa82ea52af5ce897d9275c553477087ece7fb1e20eefca
3
+ size 9024188