3

I'm trying to beat a game made by my friend. The game goes as follows:

A baby will spawn at a random location on my screen. i then have to move the mouse over it, and react,by clicking it, as soon as it starts to scream.

I have used the java.awt.Robot to manouver the mouse the the baby.

My problem now, is that i wan't to click it whenever the sound spikes, by setting a threshold of some sort, but i cannot find a way to measure outgoing volume.

I have tried to utilize javax.sound.sampled.*, but that only lets me access the sound from the microphone.

Ideally there would be a fuction like LineOut.GetVolume(), but i doubt i am that lucky :P

Any suggestions on how to access the outgoing volume in java, would be greatly appreciated :D

Kind Regards Frederik

  • Isn't volume controlled at OS level? Also the way you described the game makes it sound like whack-a-baby, which is mildly disturbing... just kidding... – jingx May 22 '18 at 15:27
  • it is a whack a baby game :p we just make stupid games for each other to practice programming, and finding ways to program solutions :P I believe the volume is controlled at OS level, but i don't want to control it, i just want to react to a change in it :) – user9829415 May 22 '18 at 15:33
  • https://docs.oracle.com/javase/tutorial/sound/accessing.html It seems like you can switch from microphone to the proper line? – rilent May 22 '18 at 15:43
  • i cant switch the line i am recording :/ i can get info of the speakers by doing: Port line = (Port) AudioSystem.getLine(Port.Info.SPEAKER);, but cant seem to find the volume anywhere :/ – user9829415 May 22 '18 at 16:30
  • The Java Sound APIs will only tell you about sounds being made by the current JVM. They won't tell you anything about sounds from other programs, not even the volume. – greg-449 May 22 '18 at 16:37
  • Are you complete sure about that? The only other solution i can think of, is checing the pixelvalues of the volume slider that is build into windows, and that is far from ideal :P – user9829415 May 22 '18 at 16:50
  • From the line that has audio info, I believe you are going to have to decode it from bytes into PCM values, and calculate and monitor a rolling root-mean-square of the values to obtain a relative volume. A TargetDataLine is used to get the audio stream and an example of how to do so is on the tutorial link given by rilent above. – Phil Freihofner May 23 '18 at 15:39

0 Answers0