How to accurately measure microphone input volume (dB/magnitude) for AI detection?

Hi everyone,

I’m currently working on a horror game where the enemy AI (I’m using LimboAI) listens to the player’s real-life microphone. I want the monster to detect when the player makes too much noise in real life (like talking, coughing, or hitting the keyboard).

I know that I need to route an AudioStreamMicrophone to a muted Audio Bus to prevent audio feedback loop. However, I’m a bit confused about the best coding approach to actually read the volume levels in _process(delta).

Should I use AudioServer.get_bus_peak_volume_left_db() to get the decibels, or is it better to use AudioEffectSpectrumAnalyzer to get the magnitude for a specific frequency range (to filter out background static)?

If anyone has experience with this kind of mechanic or a solid code snippet for reading microphone levels without tanking performance, I would really appreciate the help!

Thanks in advance!

I found https://www.youtube.com/watch?v=cMEw2XQOgXM

Oh that sounds amazing! What a fantastic idea! I can just imagine someone walking into the room you are in and talking and whispering to them “Be quiet, the monster will hear you”. Wow. Such a great idea!

thank you but no coop