Measuring loudness of an audio stream using python not working

Viewed 228

I'm trying to analyze an audio stream, taking it block by block and measuring loudness. I have tried multiple libraries, but the result seems to be constant no matter what I do. After writing the blocks in a file, the file plays back the sound.

Even though there is a background noise from the microphone, I believe that talking/screaming should peak higher than the noise.

My script looks like this: (I can't give the actual link, it's a stream on darkice)

import requests
import numpy
import math

ambient_db = -2.4

stream_url = 'http://my-stream-url.mp3' 
r = requests.get(stream_url, stream=True)

with open('stream.mp3', 'wb') as f:
    try:
        for block in r.iter_content(1024):
            samps = numpy.fromstring(block, dtype = numpy.int16)

            rms = numpy.sqrt(numpy.mean(samps**2))
            db = 20*numpy.log10(rms)
            print(db)
    except KeyboardInterrupt:
        pass

Output of the above looks like this: output even when screaming into the microphone

What can I do?

0 Answers
Related