diff options
| -rw-r--r-- | speakerSqeaker.txt | 20 | ||||
| -rw-r--r-- | speakerSqueaker.service | 4 | ||||
| -rwxr-xr-x | speakerSqueaker.sh | 33 |
3 files changed, 45 insertions, 12 deletions
diff --git a/speakerSqeaker.txt b/speakerSqeaker.txt index d78c40a..bb4e8a6 100644 --- a/speakerSqeaker.txt +++ b/speakerSqeaker.txt @@ -63,3 +63,23 @@ play -n synth 1 sine 40 fade .2 0 40 Hz fade fade in from zero volume to max volume over 200 msec. '0' says fade out at end over same period. + + +Communicate with journald: +echo hello $USER | systemd-cat -t AlexySayle -p warning + -t lable the source of the message + -p priority level - affects colour in logfile. + Alert creates a bell (hw speaker beep) (ASCII 0x07) +RED +Jan 27 13:07:40 cr4y Tui the Dog[5693]: Thu, 27 Jan 2022 13:07:40 +1100 woof woof alert +Jan 27 13:07:52 cr4y Tui the Dog[5697]: Thu, 27 Jan 2022 13:07:52 +1100 woof woof crit +Jan 27 13:08:02 cr4y Tui the Dog[5701]: Thu, 27 Jan 2022 13:08:02 +1100 woof woof err +Yellow, bold +Jan 27 13:08:14 cr4y Tui the Dog[5704]: Thu, 27 Jan 2022 13:08:14 +1100 woof woof warning +Green, bold +Jan 27 13:08:28 cr4y Tui the Dog[5707]: Thu, 27 Jan 2022 13:08:28 +1100 woof woof notice +Green (default) +Jan 27 13:08:40 cr4y Tui the Dog[5710]: Thu, 27 Jan 2022 13:08:40 +1100 woof woof info +Grey +Jan 27 13:08:50 cr4y Tui the Dog[5713]: Thu, 27 Jan 2022 13:08:50 +1100 woof woof debug + diff --git a/speakerSqueaker.service b/speakerSqueaker.service index 8a43108..f52f0cc 100644 --- a/speakerSqueaker.service +++ b/speakerSqueaker.service @@ -5,8 +5,8 @@ After=sound.target [Service] Type=oneshot -StandardOutput=journal -ExecStart=-/usr/local/bin/speakerWatchdog.sh +#StandardOutput=journal +ExecStart=-/usr/local/bin/speakerSqueaker.sh [Install] WantedBy=default.target diff --git a/speakerSqueaker.sh b/speakerSqueaker.sh index 78450d5..17fe511 100755 --- a/speakerSqueaker.sh +++ b/speakerSqueaker.sh @@ -3,10 +3,10 @@ # # SJP 11 Dec 2021 # +# Dependencies: sox (required) +# xprintidle (not required) +# # Record a snippet of default stream: - -# 0 rec -d -n trim 0 .1 stat - # rec sox in record mode # -d default input # -n direct output to /dev/null @@ -17,27 +17,40 @@ # grep finds this line: Minimum amplitude: 0.000000 # | pipe # awk ruturns just the third word (the number) -#echo hello $USER | systemd-cat -t AlexySayle -p warning -maxAmp=$(rec -d -c1 -n trim 0 .1 stat 2>&1 | grep 'Maximum amplitude' | awk {'print $3'}) -echo Max Amplitude = $maxAmp + +maxAmp=$(rec -d -c1 -n trim 0 .1 stat 2>&1 | grep 'Maximum amp' | awk {'print $3'}) + +# xprintidle is logfile eyecandy. Not necessary for the script to work +echo $(xprintidle) Max Amplitude = "$maxAmp" | \ + systemd-cat -t "idle time (msec) & audio level " -p notice + if [ "$maxAmp" == "0.000000" ]; then - # if Max amplitude = 0 then we have silence! + # We have silence if [ -f "/tmp/silencemarker" ] ; then - # There was silence last time we checked, so play the tone - echo Play the sound + # There was silence last time we checked, so play the tone. + # Even though there may have been some sounds played since the previous + # observation, let's play it safe. + echo 'Play inaudible tone (40 Hz for 1 sec)' play -nq synth 1 sine 40 fade 0.2 0 - rm /tmp/silencemarker else touch /tmp/silencemarker fi else + # Sound was detected so remove the marker file if it is there if [ -f "/tmp/silencemarker" ] ; then rm /tmp/silencemarker fi fi +# Set a 10 minute timer. Accuracy is 'per-minute' so the interval may be +# as long as 11 minutes. This is ok for Creative Gigaworks; they turn off after 11+mins. systemd-run --user --on-active=10m /usr/local/bin/speakerSqueaker.sh +#TODO: possibly allow actual turn off if no sound has been heard for a 'long' time +#TODO: Measure actual power consumption to see how futile erp actually is +# http://eco3e.eu/regulations/erp-directive/ + + #to generate a tone that is not audible: #play -n synth 1 sine 40 fade .2 0 # |
