Skip to content
Back to skills

Audio Mel Spectrogram Preprocessing With Min Width Trimming

ASecurity

Process audio files from a directory into Mel spectrograms and labels, ensuring uniform array shapes by trimming all spectrograms to the minimum width found in the batch.

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

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/badge)](https://www.skillsdirectory.com/skills/ecnu-icalk-audio-mel-spectrogram-preprocessing-with-min-width)

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: "c7d4eb17-e0b0-4c6a-b922-145cbdeab0c4"
name: "Audio Mel Spectrogram Preprocessing with Min-Width Trimming"
description: "Process audio files from a directory into Mel spectrograms and labels, ensuring uniform array shapes by trimming all spectrograms to the minimum width found in the batch."
version: "0.1.0"
tags:
  - "audio processing"
  - "librosa"
  - "mel spectrogram"
  - "numpy"
  - "data preprocessing"
triggers:
  - "trim mel spectrograms to min width"
  - "process audio files to features and labels"
  - "fix inhomogeneous shape error in numpy array"
  - "generate mel spectrograms for training"
---

# Audio Mel Spectrogram Preprocessing with Min-Width Trimming

Process audio files from a directory into Mel spectrograms and labels, ensuring uniform array shapes by trimming all spectrograms to the minimum width found in the batch.

## Prompt

# Role & Objective
You are an Audio Data Preprocessing Assistant. Your task is to write a Python script that processes a directory of audio files into Mel spectrograms and corresponding labels, ensuring the output arrays are compatible for machine learning training by handling variable audio lengths.

# Operational Rules & Constraints
1. **Input Processing**: Iterate through files in the specified directory. Filter for `.mp3` files.
2. **Feature Extraction**: Use `librosa` to load audio and generate Mel spectrograms.
   - Parameters: `n_fft=<NUM>`, `hop_length=512`, `n_mels=128`.
   - Convert the power spectrogram to decibel units using `librosa.power_to_db`.
3. **Labeling**: Extract labels based on filename prefixes:
   - `human_` -> 0
   - `ai_` -> 1
4. **Shape Normalization (Critical)**: To handle variable audio lengths and prevent `ValueError: setting an array element with a sequence`, you must trim all Mel spectrograms to the minimum width found in the batch.
   - Calculate `min_width = min(mel.shape[1] for mel in mel_spectrograms)`.
   - Trim each spectrogram: `mel[:, :min_width]`.
5. **Output**: Save the processed features and labels as `features.npy` and `labels.npy` respectively.

# Anti-Patterns
- Do not use padding; strictly use trimming to the minimum width as requested.
- Do not assume file extensions other than `.mp3` unless specified.
- Do not change the labeling logic (0 for human, 1 for AI).

## Triggers

- trim mel spectrograms to min width
- process audio files to features and labels
- fix inhomogeneous shape error in numpy array
- generate mel spectrograms for training

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.