Making sound spectrum images from command line

Most of the audio editors are able to show us different kinds of audio analysis like this:

enter image description here

  • Wave form (whole file);
  • spectral frequency (whole file);
  • spectrum analysis (for a slice).

The generated images can be saved one way or another.

Is there a command line alternative to do this?

Windows 7. A multi-OS solution is preferred.


Solution 1:

One of three tasks could be performed with SoX:

sox file.wav -n spectrogram

Solution 2:

You can use ffmpeg to create spectrogram

ffmpeg -i inputfile.mp3 -lavfi showspectrumpic=s=800x400:mode=separate spectrogram.png

Filter documentation: https://ffmpeg.org/ffmpeg-filters.html#showspectrumpic

Solution 3:

Since I couldn't find any windows examples, I've created a batch file you might find useful for automating all flac audio files in a directory, or which ever extension you choose to run, and creating a spectrogram for it (just change the (".*.flac") to (".*.extension") if you want them for different audio files) here:

FOR %%F IN (".\*.flac") DO sox.exe "%%F" -n spectrogram -p 2 -S 5 -y 240 -c "%%~NXF" -o "%%~NF.png"

Create a text file and put that code in it and save it as filename.bat, then run it with the files you choose in the sox directory, unless specified in another place. You can modify the colors as you see fit with -p 1 to 6.