audio-visualizer 0.7.0

Audio visualization library for developers: visually check audio samples, e.g. as waveform or spectrum, either as static PNG/SVG image or live in a real-time GUI window.
Documentation

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 audio_visualizer::WaveformVisualizer;

WaveformVisualizer::new(&samples)
    .sample_rate(44100.0)
    .title("sample_1.mp3 (left channel)")
    .write_png("waveform.png")?;

Example visualization of a waveform

Static spectrum

use audio_visualizer::SpectrumVisualizer;

// spectrum: &[(f32, f32)] with (frequency in Hz, magnitude) pairs,
// e.g. computed with the spectrum-analyzer crate
Spectrum::new(&spectrum)
    .highlight(50.0)
    .highlight(250.0)
    .write_png("spectrum.png")?;

Example visualization of a spectrum

Live visualization

use audio_visualizer::live::{LiveVisualizer, Transform};
use lowpass_filter::lowpass_filter_slice;

LiveVisualizer::new(Transform::waveform(|samples, sample_rate| {
    let mut samples = samples.to_vec();
    lowpass_filter_slice(&mut samples, sample_rate, 80.0);
    samples
}))
.title("Live Audio Lowpass Filter View")
.open()?;

Real-time audio + lowpass filter

Example visualization of 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

Example visualization of real-time audio + spectrum analysis
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