# Generate a Mel Spectrogram PNG

Render a local audio file as a PNG mel spectrogram with ML-style FFT, hop, mel-band, dB, colormap, and image-size controls.

## Run it

- **CLI:** `gizza tool mel-spectrogram-generator 'url=https://example.com/input' 'input_format=base64' 'n_fft=2048' 'hop_length=0' 'n_mels=128' 'fmin=0' 'fmax=0' 'mel_scale=slaney' 'window=hann' 'scale=db' 'top_db=80' 'db_reference=peak' 'colormap=magma' 'width=1000' 'height=400' 'channel=mix' 'center=true' 'resample_hz=0'`
- **Web:** https://gizza.ai/tools/mel-spectrogram-generator/
- **Agents:** machine-readable descriptor (parameters JSON Schema) at https://gizza.ai/tools/mel-spectrogram-generator/tool.json

## Inputs

- `input` — Audio file _(file; accept: audio/*)_
- `input_format` — Input encoding _(field)_
- `n_fft` — FFT / window size (samples) _(field)_
- `hop_length` — Hop length (samples, 0 = n_fft/4) _(field)_
- `n_mels` — Mel bands _(field)_
- `fmin` — Low frequency (Hz) _(field)_
- `fmax` — High frequency (Hz, 0 = Nyquist) _(field)_
- `mel_scale` — Mel scale _(field)_
- `window` — Analysis window _(field)_
- `scale` — Intensity scale _(field)_
- `top_db` — dB dynamic range _(field)_
- `db_reference` — dB reference _(field)_
- `colormap` — Colormap _(field)_
- `width` — Output width (px, 0 = natural) _(field)_
- `height` — Output height (px, 0 = natural) _(field)_
- `channel` — Channel _(field)_
- `center` — Center frames (librosa-style padding) _(field)_
- `resample_hz` — Analysis sample rate (Hz, 0 = native) _(field)_

## Output

- Mel spectrogram (image)

## Query parameters

Open the tool pre-filled and auto-run via URL:

- `input_format` — Input encoding
- `n_fft` — FFT / window size (samples)
- `hop_length` — Hop length (samples, 0 = n_fft/4)
- `n_mels` — Mel bands
- `fmin` — Low frequency (Hz)
- `fmax` — High frequency (Hz, 0 = Nyquist)
- `mel_scale` — Mel scale
- `window` — Analysis window
- `scale` — Intensity scale
- `top_db` — dB dynamic range
- `db_reference` — dB reference
- `colormap` — Colormap
- `width` — Output width (px, 0 = natural)
- `height` — Output height (px, 0 = natural)
- `channel` — Channel
- `center` — Center frames (librosa-style padding)
- `resample_hz` — Analysis sample rate (Hz, 0 = native)
- `url` — fetch the input file from a public URL (CORS-permitting)

Example: `https://gizza.ai/tools/mel-spectrogram-generator/?url=https://example.com/input&input_format=base64&n_fft=2048&hop_length=0&n_mels=128&fmin=0&fmax=0&mel_scale=slaney&window=hann&scale=db&top_db=80&db_reference=peak&colormap=magma&width=1000&height=400&channel=mix&center=true&resample_hz=0`

---

## About this tool

Mel spectrograms compress an audio clip into the time-frequency view used by many speech, music, keyword-spotting, and audio-classification pipelines. This tool decodes the audio locally, applies an STFT, maps FFT bins through triangular mel filters, scales the energy, and renders the result as a PNG image.

Worked example: upload a WAV voice clip, choose the “Speech 16 kHz compact” preset, and download the PNG. The output uses 80 mel bands, a 1024-sample FFT, a 256-sample hop, an 8 kHz high-frequency edge, and a 16 kHz analysis sample rate — a compact diagnostic view for speech models.

Limits: input audio is capped at 24 MiB and 4,000,000 decoded samples. Very short clips may need `center=true` or a smaller FFT. `width=0` and `height=0` use the natural matrix size: one pixel per frame and one row per mel band.

## FAQ

<details>
<summary>Is this the same as an MFCC extractor?</summary>

No. A mel spectrogram keeps the mel-band energy image before the DCT step. MFCC tools convert the log-mel bands into cepstral coefficients for tabular features; this tool renders the mel bands directly as a PNG for inspection or image-based pipelines.

</details>

<details>
<summary>Which settings match common audio-ML examples?</summary>

A common starting point is `n_fft=2048`, `hop_length=512`, `n_mels=128`, `mel_scale=slaney`, `scale=db`, and `center=true`, which mirrors the defaults many librosa-style examples use. Speech pipelines often resample to 16 kHz and use 64 or 80 mel bands.

</details>

<details>
<summary>Why are low frequencies at the bottom of the PNG?</summary>

That orientation matches the way spectrograms are usually read: time runs left to right and frequency rises from bottom to top. The summary reports the loudest mel-band frequency so you can sanity-check tones and hums.

</details>

<details>
<summary>What do `peak` and `full_scale` dB references change?</summary>

`peak` maps the loudest cell in the clip to the brightest color, which is useful for visual contrast. `full_scale` keeps the reference tied to digital full scale, so quiet files stay visibly dimmer and are easier to compare across clips.

</details>

## Related tools

- [Export Audio Features to CSV](https://gizza.ai/tools/audio-feature-csv-exporter/): Export per-frame audio features — RMS, spectral centroid, ZCR, rolloff, flatness, bandwidth, flux — to CSV, TSV, or JSON. Runs in your browser.
- [Extract MFCC Features from Audio](https://gizza.ai/tools/mfcc-extractor/): Extract MFCC features from audio as CSV, TSV, or JSON. Tune speech defaults, librosa-style settings, deltas, and sample-rate options locally.
- [Waveform Image from Audio](https://gizza.ai/tools/waveform-image/): Turn any audio file into a waveform PNG in your browser — pick the size, solid or gradient wave colors and background, or keep it transparent. Nothing is uploaded.
- [Convert AIFF to FLAC](https://gizza.ai/tools/aiff-to-flac/): Convert AIFF or AIF audio to lossless FLAC in your browser — preserve samples and textual tags, choose FLAC compression level 0-12, and download the result.
- [Convert AIFF to WAV](https://gizza.ai/tools/aiff-to-wav/): Free AIFF to WAV converter that runs in your browser. Choose the PCM bit depth, sample rate and channel layout — at a matching depth the samples are identical.
