A professional Python tool for generating high-quality spectrogram visualizations from WAV audio files. Performs digital signal processing using customizable Fast Fourier Transform (FFT) parameters.
- Multiple window functions: Hann, Hamming, and Blackman windows to reduce spectral leakage
- Customizable FFT parameters: Adjustable frame size and hop size for different analysis needs
- High-quality visualization: Configurable figure dimensions and color maps
- Professional output: Black background with publication-ready quality
- Raw WAV processing: Direct audio file reading without external dependencies
- Fast Fourier Transform (FFT) for frequency domain analysis
- Logarithmic dB scaling for accurate intensity representation
- Mono conversion for stereo WAV files
- Support for all WAV formats: 8-bit to 32-bit PCM audio
- Python 3
- NumPy (scientific computing and FFT)
- Matplotlib (visualization)
- Standard library (wave, struct - no external audio dependencies)
- Clone this repository:
git clone https://github.com/gahlii/wav_spectrogram_generator.git
cd wav_spectrogram_generator- Install dependencies:
pip install -r requirements.txt- Run the spectrogram generator:
python spectrogram.py --input audio.wav --output spectrogram.png# Basic usage
python spectrogram.py --input audio.wav --output spectrogram.png
# Custom FFT parameters
python spectrogram.py --input audio.wav --output spec.png --frame_size 2048 --hop_size 256 --window hamming
# High-resolution output
python spectrogram.py --input audio.wav --output spec.png --width 16 --height 8 --cmap viridis
# If the audio file is in the same directory as the script
python spectrogram.py --input audio.wav --output spectrogram.png
# If the audio file is in a different directory
python spectrogram.py --input ../audio_files/sample.wav --output ./images/spectrogram.png
# Using absolute path
python spectrogram.py --input /home/user/audio.wav --output /home/user/spectrogram.png
--input: Input WAV file path (required)
--output: Output image file path (required)
--frame_size: FFT window size (256, 512, 1024, 2048, 4096)
--hop_size: Step between analysis frames
--window: Window function (hann, hamming, blackman)
--cmap: Color map for visualization
--width, --height: Figure dimensions in inches
For best results, organize your files as follows:
wav_spectrogram_generator/
├── spectrogram.py # Main script
├── requirements.txt # Dependencies
├── audio/ # Recommended: place audio files here
│ └── sample1.wav
├── output/ # Recommended: output folder for images
│ └── spectro1.png
└── README.md
