Skip to content

Instantly share code, notes, and snippets.

@tinpark
Forked from hrywlms/generate sox spectrograms.sh
Last active July 10, 2018 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tinpark/ee42c6804ecb23fda638454110aaf6ab to your computer and use it in GitHub Desktop.
Save tinpark/ee42c6804ecb23fda638454110aaf6ab to your computer and use it in GitHub Desktop.
A quick way to generate spectrograms for a bunch of audio files
### Generate PNG spectrograms using SoX
### Use the input file name as the title within the image as well as the output file name
### Set the width to 2000 (seems to output a ~2140px wide image)
### Generate for five arguments,
### arg 1 = file type to make spectrograms from, e.g. .wav,
### arg 2 = width of the spectrogram
### arg 3 = hight of the spectrogram
### arg 4 = the dB level of sounds to pick out, ignoring sounds below that threshold
### arg 5 = the frequencies to hone in on e.g. 4k will give you a spectrogram that draws sounds up to 2k
### usage: bash makeSpectrogram.sh wav 900 600 70 4k, renders a spectrogram 900*600 pixels from every wav file
### in your folder focusing on frequenceies below 2k and sounds crossing the 70dB threshold
for file in *.$1;do
outfile="${file%.*}.png"
title_in_pic="${file%.*} $5 all sound above $4dB"
sox "$file" -r $5 -n rate spectrogram -t "$title_in_pic" -x $2 -y $3 -z $4 -o "$outfile"
done
@tinpark
Copy link
Author

tinpark commented Mar 2, 2018

modded script to include arguments for
file type
width of spectrogram
frequency range
e.g.: bash makeSpectrogram.sh wav 900 4k, renders a spectrogram 1044 pixels wide from every wav file in your folder focusing on frequenceies below 2k

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment