Decibel values at specific points in wav file

2020-03-26 02:12发布

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.

enter image description here

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

2条回答
萌系小妹纸
2楼-- · 2020-03-26 02:18

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

查看更多
Root(大扎)
3楼-- · 2020-03-26 02:36

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:

from scipy.io.wavfile import read
samprate, wavdata = read('file.wav')

We then split the file into chunks, where the number of chunks depends on how finely you want to measure the volume:

import numpy as np
chunks = np.array_split(wavdata, numchunks)

Finally, we compute the volume of each chunk:

dbs = [20*log10( sqrt(mean(chunk**2)) ) for chunk in chunks]

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)

查看更多
登录 后发表回答