sound processing - avarage amplitude?

Christos TZOTZIOY Georgiou tzot at sil-tec.gr
Sun Mar 20 05:14:54 EST 2005


On Sat, 19 Mar 2005 17:18:42 +0200, rumours say that Niklas Paro <nparo at abo.fi>
might have written:

>Hello
>
>I would need way to check the amplitude (over time) for a sound file in
>python. I'm sure this can be done, for example the audioop.rms function
>seems to be able return amplitude values. However, it would be really
>great to get the results in dB, which does not seem to be the case.
>Anyone who has more information about this, or a way to convert the
>results? I've searched google but info about audioop seem to be quite
>scarce. Also, does audioop function perfectly also for wave files? Also,
>cross-platform solutions are of course preferred, but I'm running linux
>(with oss).

audioop is platform independent.  You just might need to import wave also.

>I've also looked somewhat into tkSnack (http://www.speech.kth.se/snack/)
>which has a dBPowerSpectrum function which might be doing at least
>partially what i want it to, however, the returned values are approx.
>-100 ... which I find odd. The "real", recorded sound was somewhere in
>the 50-60dB range.

Where is your 0dB mark?  If it's at maximum amplitude (1), then any value
(except zero) can be expressed as (negative) dB by the following function:

def amp2dB(amplitude):
	return 20*math.log(amplitude, 10)

If you're converting from the 0...32767 range of 16bit PCM files, first divide
the amplitude by 32767.0 and pass the result to amp2dB.

>thanks in advance

Hope this helps.
-- 
TZOTZIOY, I speak England very best.
"Be strict when sending and tolerant when receiving." (from RFC1958)
I really should keep that in mind when talking with people, actually...



More information about the Python-list mailing list