I'm looking to find the current decibel level in a room using a microphone and setting it as a variable. I haven't been able to find any python code on this so I'm very stuck.
It would be good if the variable could refresh every 0.3 of a second but it doesn't have to.
Thanks for your help!!
Here is some python code using the
pyaudio librarythat can calculate the dB level using Root Mean Square (RMS) and print it every 0.3 seconds. Both thermsanddbare available as variables.Note
As mentioned in the comment above - measuring dB can be a deeper topic than perhaps you require here. Without some info about the usecase, just note that although the method here is the most common you'll likely see - it only compares peaks to itself. This question has a great discussion about this.
If you need a real world measurement of decibels, you'll need reference measurements, calibrated equipment and a little more research!