Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

How do I make a machine “blank screen” for a period of time (as a penalty) if certain noise.....

I ssh into the game computer and do:
chvt 3;  sleep 15;  chvt 7 


This will turn off the screen for 15 seconds on Linux. I've told them that the computer doesn't like loud noises. They totally believe this and beg the computer for forgiveness. They became much quieter, but not to the level that I would be happy, and so I need to continue this educational process. However, I am not always around to do this manually.

Is it possible to automate this? A microphone is attached to the box. If the level of loudness passes some threshold then I want to run a command.
by

2 Answers

espadacoder11
You can get information from the microphone by doing something like:

arecord -d1 /dev/null -vvv

You might have to play with the settings a little, such as:

arecord -d1 -Dhw:0 -c2 -fS16_LE /dev/null -vvv

From there on out, it's a simple matter of parsing the output.
sandhya6gczb
My 2 cents for the C or C++ solution: maybe not the most effective approach, but on Linux, you can use the ALSA API (built-in audio handling library of Linux) and use some numerical technique (for example, calculating the average sound level each second) to obtain the level of noise.

Then you can check it in an infinite loop, and if it's greater than a preset treshold, you can use the X11 library to turn off the screen for some seconds, or alternatively (less elegant, but it works) invoke the chvt command using system("chvt 3; sleep 15; chvt 7 ");.

Login / Signup to Answer the Question.