announcement-box/bin/pa-lib

110 lines
2.0 KiB
Plaintext
Raw Normal View History

#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
export ROOT=`dirname "$DIR"`
export SOUNDS=$ROOT/sounds
export PLAYER=mplayer
export SPEAK=espeak-ng
2021-01-09 13:22:58 +00:00
ALARM_PID=-1
STATIC_PID=-1
function info() {
echo "[INFO]" $@
}
function play() {
2021-01-09 13:22:58 +00:00
cat /dev/null | $PLAYER $@ > /dev/null 2>&1
}
function pa-volume() {
amixer cset numid=3,iface=MIXER,name='Line Out Playback Volume' $1 > /dev/null
}
function pa-volume-normal() {
2020-12-14 16:23:50 +00:00
info "Volume set to Normal"
pa-volume 15
}
function pa-volume-loud() {
2020-12-14 16:23:50 +00:00
info "Volume set to HIGH!"
pa-volume 25
}
2020-12-17 19:08:59 +00:00
function pa-volume-loud-if-inactive() {
LAST_ACTIVE=`human-activity-ago`
if [[ $LAST_ACTIVE > 200 ]]; then
info "Human is inactive. Last activity: $LAST_ACTIVE seconds ago."
pa-volume-loud
else
info "Human is active. Setting only normal volume."
pa-volume-normal
fi
}
function pa-volume-quiet() {
2020-12-14 16:23:50 +00:00
info "Volume set to low"
pa-volume 8
}
function pa-preheat() {
info "PA Preheating"
pa-power off
pa-volume-normal
2021-01-09 13:22:58 +00:00
pa-static-start 40
play $SOUNDS/announcement_4-tone_up_quick.ogg
pa-power on
info "PA Ready"
}
function pa-shutdown() {
info "PA Shutdown"
pa-power off
pa-volume-normal
2021-01-09 13:22:58 +00:00
killall $PLAYER >/dev/null 2>&1
}
function pa-announcement() {
info " DING DONG "
play $SOUNDS/announcement_4-tone_up_smooth.ogg
}
function pa-announcement-quick() {
info " Ding Dong "
play $SOUNDS/announcement_4-tone_up_smooth_quick.ogg
}
function pa-announcement-quickest() {
info " ding-dong "
play $SOUNDS/announcement_4-tone_up_quickest.ogg
}
2020-12-14 16:23:50 +00:00
function pa-alarm-start() {
info "Alarm started"
2021-01-09 13:22:58 +00:00
kill $ALARM_PID 2>/dev/null
2020-12-14 16:23:50 +00:00
play -loop 0 $SOUNDS/alarm_simple.ogg &
2021-01-09 13:22:58 +00:00
ALARM_PID=$!
2020-12-14 16:23:50 +00:00
}
function pa-alarm-stop() {
info "Alarm stopped"
2021-01-09 13:22:58 +00:00
kill $ALARM_PID 2>/dev/null
}
function pa-static-start() {
kill $STATIC_PID 2>/dev/null
play -loop 0 -volume ${1:--1} -softvol $SOUNDS/static.ogg &
STATIC_PID=$!
}
function pa-static-stop() {
kill $STATIC_PID 2>/dev/null
2020-12-14 16:23:50 +00:00
}
function pa-say() {
info "Say: $@"
2021-01-09 13:22:58 +00:00
cat /dev/null | $SPEAK "$@"
}