A real-time audio spectrogram visualizer that displays frequency spectrum and spectrograms of audio loopback devices. Available in both Python and Rust implementations.
- Real-time Visualization: View live audio spectrograms and frequency responses
- Dual Display Modes: Switch between spectrogram view and frequency response view
- Stereo Channel Support: Separate visualization for left and right audio channels
- Configurable Parameters:
- Sample rate (8kHz to 96kHz)
- FFT size (512 to 16384 points)
- Frequency scale (Linear/Logarithmic)
- Color maps (viridis, plasma, magma, inferno, turbo, cividis)
- Dynamic range control (dB min/max)
- Automatic Device Detection: Automatically finds and uses audio loopback devices
- Cross-Platform Support: Works on Windows, Linux, and macOS (with appropriate audio setup)
This repository provides two implementations:
- Python Version (
realtime_spectrogram.py) - Full-featured GUI with PyQt6 - Rust Version (
spectrogram-rs/) - High-performance alternative using egui
- Python 3.8 or higher (PyQt6 requirement)
- Audio loopback device (varies by platform - see Platform-Specific Setup below)
Install the required Python packages:
pip install -r requirements.txtThe following packages will be installed:
numpy- Numerical computingscipy- Signal processing (FFT windows)soundcard- Audio device accesspyqtgraph- High-performance plottingPyQt6- GUI frameworkmatplotlib- Color maps
python realtime_spectrogram.pyOr use the windowless version (no console on Windows):
pythonw realtime_spectrogram.pyw- Rust 1.56 or higher (edition 2021, install from rust-lang.org)
- Audio loopback device
# Build the Rust version
python build_rust.pyOr build manually:
cd spectrogram-rs
cargo build --release./dist/spectrogram-rs
# or on Windows:
.\dist\spectrogram-rs.exeCommand-line options:
spectrogram-rs --chunk 1024 --sample-rate 44100Option 1: Using "Stereo Mix" (Realtek/Windows Audio)
- Right-click the speaker icon in the system tray
- Select "Sound settings" → "Sound Control Panel"
- Go to the "Recording" tab
- Right-click in the empty area and enable "Show Disabled Devices"
- Right-click "Stereo Mix" and select "Enable"
- Set "Stereo Mix" as the default recording device (optional)
Option 2: Using Virtual Audio Cable
- Install VB-Audio Virtual Cable or similar software
- Configure your audio to route through the virtual cable
Using PulseAudio/PipeWire
The application can typically access monitor devices automatically. If needed:
# List audio sources
pactl list sources
# Load loopback module manually (if needed)
pactl load-module module-loopbackFor ALSA, you may need to set up a loopback device:
sudo modprobe snd-aloopmacOS doesn't provide a built-in loopback device. You'll need third-party software:
Option 1: BlackHole (Free, recommended)
- Download from existential.audio/blackhole
- Install and restart
- Create a Multi-Output Device in Audio MIDI Setup to combine BlackHole with your speakers
Option 2: Loopback by Rogue Amoeba (Commercial)
- More features but requires purchase
- Start the application - The app will automatically search for a suitable loopback device
- Click "Start Audio" - Begin real-time visualization
- Switch Display Modes:
- Spectrogram: Shows frequency content over time with color-coded intensity
- Frequency Response: Shows instantaneous frequency spectrum
- Open Configuration - Click "Configuration..." to adjust:
- Sample rate and FFT size
- Frequency scale (Linear/Logarithmic)
- Color map
- Dynamic range (dB min/max)
- Frequency response headroom
- Verbose console output
- Warning suppression
- Start Audio: Begin capturing and visualizing audio
- Stop Audio: Stop the audio stream
- Display Radio Buttons: Toggle between Spectrogram and Frequency Response views
- Configuration: Access settings dialog
- Left Channel: Top spectrogram/blue line in frequency response
- Right Channel: Bottom spectrogram/red line in frequency response
- Time Range: Fixed 10-second history for spectrograms
- Frequency Range: Configurable, defaults to 10 Hz to Nyquist frequency
Error: "Could not find a suitable audio loopback device"
Solutions:
- Ensure a loopback device is enabled (see Platform-Specific Setup)
- Check that the device is not in use by another application
- Try restarting the application with administrator/root privileges
- Enable "Verbose Console Output" in Configuration to see detailed device detection logs
If you see frequent discontinuity warnings:
- Try increasing the chunk size/FFT size in Configuration
- Close other audio applications that might be competing for the device
- Enable "Suppress Discontinuity Warnings" in Configuration to hide these messages
For better performance:
- Reduce the FFT size (e.g., 1024 or 512)
- Lower the sample rate (e.g., 22050 or 16000 Hz)
- Consider using the Rust version for better performance
- Close unnecessary applications
A PyInstaller spec file is included:
pyinstaller realtime_spectrogram.specThe executable will be created in the dist/ directory.
The Rust version builds a standalone executable:
python build_rust.pyOr:
cd spectrogram-rs
cargo build --release- Audio Processing: Runs in a separate QThread to avoid blocking the GUI
- FFT: Uses NumPy's FFT with scipy windows (Hann window by default)
- Visualization: PyQtGraph for high-performance real-time plotting
- Update Rate: ~25 FPS (40ms intervals) for GUI updates
- History: Rolling buffer maintaining 10 seconds of spectrogram data
- Audio Backend: CPAL for cross-platform audio input
- FFT: RustFFT library
- GUI: egui framework for immediate mode GUI
- Performance: Optimized for low latency and high frame rates
This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.
Copyright © 2025 Richard M. Hamilton
Contributions are welcome! Please feel free to submit issues or pull requests.
- Built with PyQt6, PyQtGraph, NumPy, and SciPy
- Rust version uses CPAL, RustFFT, and egui
- Inspired by audio analysis and music production tools