I am trying to measure the lead in and lead out of a wav file. Preferably the first and last 5 seconds or so. I am basically trying to assign a numerical value that means 'This song has a slow lead in' or 'This song has an abrupt end'.
My thinking has been to get the slope of the dB values, but I can't seem to find a linux command line tool that will give me dB values. I know they can be measured because Audacity has a waveform(db) view.
Basically I'm looking for a way to gather the data points to duplicate this graph so I can get the slope.
EDIT - working in java
Here are just a few of the questions on SO about reading audio files and drawing waveforms and waveform overviews in Java.
How can I create a sound file in Java
How can I draw sound data from my wav file?
Java Program to create a PNG waveform for an audio file
I don't know of any command-line tools to do this, but writing a python script with this functionality is fairly simple using
scipy
libraries.We can use
scipy.io.wavfile
to do the file IO, and then calculate the dB values ourselves (note that these won't necessarily be standard dB values, as those will depend on your speakers and volume settings).First we get the file:
We then split the file into chunks, where the number of chunks depends on how finely you want to measure the volume:
Finally, we compute the volume of each chunk:
where
dbs
is now a list of dB values (again, not necessarily the true SPL sound levels) for each chunk of your file.You can also easily split up the data in a different way, using overlapping chunks, etc.
References: - scipy.io.wavfile - dB (SPL)