Skip to content
Back to skills

Audio Mel Spectrogram Preprocessing With Min Width Trimming

ASecurity

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.

  • 611 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added November 11, 2026
ai-agents

Security analysis

A100/100

Scanned November 11, 2026

npx -y skills add ECNU-ICALK/AutoSkill --skill audio-mel-spectrogram-preprocessing-with-min-width-trimming --agent claude-code

Installs 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 with every re-scan.

Security grade badge for Audio Mel Spectrogram Preprocessing With Min Width Trimming
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ecnu-icalk-audio-mel-spectrogram-preprocessing-with-min-width-autoskill/badge)](https://www.skillsdirectory.com/skills/ecnu-icalk-audio-mel-spectrogram-preprocessing-with-min-width-autoskill)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
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

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.