Rust library: audio-visualizer
Debug audio data visually. This library targets developers who work on audio algorithms and want to quickly check that samples, filters, or spectra look as expected.
All functionality works on mono f32 samples, typically amplitudes in
[-1.0, 1.0]. Interleaved stereo data can be split with
deinterleave_stereo().
Covered Functionality
- static waveform → PNG file or SVG string, with axes and time labels; each pixel column shows the min/max amplitude of the samples it covers, so peaks stay visible (a line through every n-th sample would hide them)
- static spectrum → PNG file or SVG string, with optional highlighting of expected peaks (pairs well with the spectrum-analyzer crate)
- live visualization: records audio (always mono; stereo is averaged) from an input device and displays the real-time waveform together with a custom transformation (lowpass filter, spectrum, signal power, ...) in a GUI window (egui); cross-platform (Windows/WASAPI, Linux/ALSA, macOS/coreaudio)
(Code) Examples
There are several runnable examples in the examples/ directory.
Static waveform
use WaveformVisualizer;
new
.sample_rate
.title
.write_png?;

Static spectrum
use SpectrumVisualizer;
// spectrum: &[(f32, f32)] with (frequency in Hz, magnitude) pairs,
// e.g. computed with the spectrum-analyzer crate
new
.highlight
.highlight
.write_png?;

Live visualization
use ;
use lowpass_filter_slice;
new
.title
.open?;
Real-time audio + lowpass filter
On the top you see the original waveform of the song Holiday by Green Day.
On the bottom you see the data after a lowpass filter was applied. The beats
are visible.
Real-time audio + frequency spectrum
On the top you see the original waveform of the song Holiday by Green Day.
On the bottom you see the frequency spectrum of the latest ~46ms of audio.
Frequencies <2000Hz are clearly present.
MSRV
The MSRV is 1.95.0 stable.
Troubleshooting
Linux
- make sure to have these required packages installed:
sudo apt install libasound2-dev libxkbcommon-dev - the live visualization uses Wayland; there is no X11 backend