Datasets:
Delete create_metadata.py
Browse files- create_metadata.py +0 -58
create_metadata.py
DELETED
|
@@ -1,58 +0,0 @@
|
|
| 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.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|