How to create spectrograms using SoX

This guide will help you create spectrograms for FLAC files.

Head over to the SourceForge website where you can get the latest version of SoX – Sound eXchange.

The spectrograms will be three different images showing the following:

1. The full song length, named songtitle_sox_spectrogram.png
2. A zoom in on 3 seconds at 1:30, named songtitle_sox_spectrogram_3_seconds-at_1_30.png
3. The last 10 seonds, named songtitle_sox_spectrogram_last_10_seconds.png

Create batch script file called “sox_spectrogram.bat” and place this inside the SoX installation folder.

Creating the batch file.

Inside the batch file copy and paste the following and then save the file:

set subdirname=spectrograms

%~d1
if not exist "%~dp1%subdirname%\" mkdir "%~dp1%subdirname%\"

%~d0
cd %~p0

FOR %%A IN (%*) DO sox %%A -n remix 1 spectrogram -t "%%~nxA" -x 3000 -y 513 -z 120 -w Kaiser -o "%~dp1%subdirname%\%%~nA_sox_spectrogram.png"

FOR %%A IN (%*) DO sox %%A -n remix 1 spectrogram -t "%%~nxA" -X 500 -y 1025 -z 120 -w Kaiser -S 1:00 -d 0:02 -o "%~dp1%subdirname%\%%~nA_sox_spectrogram_zoom.png"

FOR %%A IN (%*) DO sox %%A -n trim -10 remix 1 spectrogram -t "%%~nxA" -x 3000 -y 1025 -o "%~dp1%subdirname%\%%~nA_sox_spectrogram_zoom_last-10seconds.png"

pause

Next create a shortcut to the batch file in your “Send to” directory. This can be found here:

C:\Users\USERNAME\AppData\Roaming\Microsoft\Windows\SendTo\

Right click on a .flac file and choose “Send to” and then pick the newly created batch file.

The Windows "Send to" menu.

A command prompt window will popup and start to do its thing. After a minute or so the spectrograms will appear inside a subfolder called “spectrograms” ready to be viewed.

The completed spectrograms.
Share this post: