Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Visualize audio as mel spectrograms, chromagrams, MFCC (librosa)
| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-01 | ✗→✓ | ▲ Improved | 91% | 0% |
| case-17 | ✗→✓ | ▲ Improved | 73% | 0% |
| case-05 | ✗→✓ | ▲ Improved | 56% | 0% |
| case-09 | ✗→✓ | ▲ Improved | 41% | 0% |
| case-12 | ✗→✓ | ▲ Improved | 63% | 0% |
Visualize audio files as mel spectrograms, chromagrams, and MFCC feature plots using the librosa Python library. Useful for music analysis, speech processing, and audio debugging.
powershellpip install librosa matplotlib soundfile
pythonimport librosa import librosa.display import matplotlib.pyplot as plt import numpy as np def mel_spectrogram(audio_path, output="mel_spec.png"): y, sr = librosa.load(audio_path, sr=None) S = librosa.feature.melspectrogram(y=y, sr=sr, n_mels=128, fmax=8000) S_db = librosa.power_to_db(S, ref=np.max) fig, ax = plt.subplots(figsize=(12, 4), facecolor="#0d1117") ax.set_facecolor("#0d1117") img = librosa.display.specshow(S_db, sr=sr, x_axis="time", y_axis="mel", fmax=8000, ax=ax, cmap="magma") fig.colorbar(img, ax=ax, format="%+2.0f dB", label="dB") ax.set_title(f"Mel Spectrogram — {audio_path}", color="white") ax.tick_params(colors="white") ax.xaxis.label.set_color("white") ax.yaxis.label.set_color("white") plt.tight_layout() plt.savefig(output, dpi=150, bbox_inches="tight") plt.close() print(f"Saved: {output}") mel_spectrogram("song.mp3")
pythonimport librosa, librosa.display, matplotlib.pyplot as plt def chromagram(audio_path, output="chroma.png"): y, sr = librosa.load(audio_path, sr=None) chroma = librosa.feature.chroma_cqt(y=y, sr=sr) fig, ax = plt.subplots(figsize=(12, 4), facecolor="#0d1117") ax.set_facecolor("#0d1117") img = librosa.display.specshow(chroma, y_axis="chroma", x_axis="time", ax=ax, cmap="coolwarm") fig.colorbar(img, ax=ax) ax.set_title("Chromagram", color="white") ax.tick_params(colors="white") plt.tight_layout() plt.savefig(output, dpi=150, bbox_inches="tight") plt.close() print(f"Saved: {output}") chromagram("song.mp3")
pythonimport librosa, librosa.display, matplotlib.pyplot as plt import numpy as np def mfcc_plot(audio_path, n_mfcc=20, output="mfcc.png"): y, sr = librosa.load(audio_path, sr=None) mfccs = librosa.feature.mfcc(y=y, sr=sr, n_mfcc=n_mfcc) fig, ax = plt.subplots(figsize=(12, 4), facecolor="#0d1117") ax.set_facecolor("#0d1117") img = librosa.display.specshow(mfccs, x_axis="time", ax=ax, cmap="viridis") fig.colorbar(img, ax=ax) ax.set_title(f"MFCC ({n_mfcc} coefficients)", color="white") ax.tick_params(colors="white") plt.tight_layout() plt.savefig(output, dpi=150, bbox_inches="tight") plt.close() print(f"Saved: {output}") mfcc_plot("speech.wav", n_mfcc=13)
pythondef analyze_audio(audio_path): base = audio_path.rsplit(".", 1)[0] mel_spectrogram(audio_path, output=f"{base}_mel.png") chromagram(audio_path, output=f"{base}_chroma.png") mfcc_plot(audio_path, output=f"{base}_mfcc.png") print(f"Analysis complete: 3 PNG files saved for {audio_path}") analyze_audio("recording.wav")
pythonimport librosa, numpy as np y, sr = librosa.load("audio.mp3", sr=None) duration = librosa.get_duration(y=y, sr=sr) tempo, _ = librosa.beat.beat_track(y=y, sr=sr) rms = np.sqrt(np.mean(y**2)) print(f"Duration: {duration:.2f} seconds") print(f"Sample rate:{sr} Hz") print(f"Tempo: {tempo:.1f} BPM") print(f"RMS energy: {rms:.4f}")
"Show me what this audio recording looks like as a spectrogram" → Use step 2 to generate a mel spectrogram PNG. Open the saved file.
"What musical key is this song in? Visualize the chroma content" → Use step 3 to generate a chromagram — peaks in chroma rows indicate dominant pitch classes.
"Generate MFCC features from this speech recording for my ML model" → Use step 4 to plot MFCCs, then extract the mfccs array for downstream ML use.
offset and duration parameters if neededlibrosa.load supports MP3, WAV, FLAC, OGG — ensure soundfile and audioread are installed for MP3 supportn_mfcc and sr — use consistent settings across all files in an ML datasetOther measured skills in the registry, with their headline benchmark lift.