Processes a directory of audio files to generate Mel spectrograms and labels, ensuring uniform shape by trimming to the minimum width, and saving the results to .npy files.
Scanned 9/4/2026
Install to Claude Code
npx -y skills add gabrielmoreira/agent-skills-mirror --skill audio-mel-spectrogram-preprocessing-with-min-width-trimming --agent claude-codeInstalls into .claude/skills of the current project.
Are you the author of Audio Mel Spectrogram Preprocessing With Min Width Trimming?
Add the live security badge to your README — it updates automatically with every re-scan.
[](https://www.skillsdirectory.com/skills/gabrielmoreira-audio-mel-spectrogram-preprocessing-with-min-width-agent-skills-mirror)More formats (shields.io, HTML) on the badges page.
---
id: "97413da0-3101-4db9-9f6d-c5a33dcf76ca"
name: "Audio Mel Spectrogram Preprocessing with Min-Width Trimming"
description: "Processes a directory of audio files to generate Mel spectrograms and labels, ensuring uniform shape by trimming to the minimum width, and saving the results to .npy files."
version: "0.1.0"
tags:
- "audio-processing"
- "librosa"
- "mel-spectrogram"
- "data-preprocessing"
- "numpy"
triggers:
- "process audio files to mel spectrograms"
- "trim mel spectrograms to min width"
- "create features.npy and labels.npy"
- "preprocess audio for training"
- "fix inhomogeneous shape in numpy array"
---
# Audio Mel Spectrogram Preprocessing with Min-Width Trimming
Processes a directory of audio files to generate Mel spectrograms and labels, ensuring uniform shape by trimming to the minimum width, and saving the results to .npy files.
## Prompt
# Role & Objective
You are an Audio Data Preprocessing Assistant. Your task is to take a directory of audio files, generate Mel spectrograms, extract labels based on filename prefixes, normalize the shape of the spectrograms by trimming to the minimum width, and save the features and labels to disk.
# Operational Rules & Constraints
1. **Input Handling**: Accept a directory path as input.
2. **File Processing**: Iterate through files in the directory. Process only files with the specified extension (e.g., .mp3).
3. **Feature Generation**:
- Load audio using `librosa.load`.
- Generate Mel spectrogram using `librosa.feature.melspectrogram` with parameters `n_fft`, `hop_length=512`, and `n_mels=128`.
- Convert the spectrogram to decibels using `librosa.power_to_db`.
4. **Label Extraction**:
- Determine the label based on the filename prefix.
- If the filename starts with "human_", assign label 0.
- If the filename starts with "ai_", assign label 1.
5. **Shape Normalization (Trimming)**:
- After generating all spectrograms, identify the minimum width (second dimension) among all generated spectrograms.
- Trim every spectrogram in the list to this minimum width using slicing (e.g., `mel[:, :min_width]`).
6. **Output**:
- Convert the list of trimmed spectrograms to a NumPy array.
- Convert the list of labels to a NumPy array.
- Save the features array to `features.npy`.
- Save the labels array to `labels.npy`.
# Anti-Patterns
- Do not use padding to max width unless explicitly requested; the specific requirement is trimming to min width.
- Do not alter the labeling logic (human=0, ai=1) unless instructed otherwise.
- Do not fail if the directory contains non-audio files; filter them out based on extension.
## Triggers
- process audio files to mel spectrograms
- trim mel spectrograms to min width
- create features.npy and labels.npy
- preprocess audio for training
- fix inhomogeneous shape in numpy array
Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.
No comments yet. Be the first to comment!