I wonder if there is a way to scan in Java for a certain volume in a predefined process. If this volume exceeds a certain dB value, a certain KeyEvent
or MouseEvent
should be executed only on this process, so this could also run in the background.
I couldn't see a good way to implement this in Java so far, so I'm also wondering if and how this is possible.
Thanks in advance!
Basic plan:
SourceDataLine
(will not work for Clip
)root mean square
for more info)For reading data exposed by the SourceDataLine
during playback, check the first example in the tutorial "Using Files and Format Converters", the point where the code reads the following:
// Here, do something useful with the audio data that's
// now in the audioBytes array...
As far as determining what RMS value corresponds to the desired trigger DB or loudness level, things can get quite complicated. Audio data is basically relative not absolute, and the values that the RMS algorithm gives can have different "perceived" loudness depending upon the frequency content of the sound. This post, How to get the volume level from PCM data discusses some of the complications encountered in this realm. But perhaps it is overthinking the issue, depending on what you are going for.