#!/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 ALARM_PID=-1 STATIC_PID=-1 function info() { echo "[INFO]" $@ } function play() { 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() { info "Volume set to Normal" pa-volume 15 } function pa-volume-loud() { info "Volume set to HIGH!" pa-volume 25 } 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() { info "Volume set to low" pa-volume 8 } function pa-preheat() { info "PA Preheating" pa-power off pa-volume-normal 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 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 } function pa-alarm-start() { info "Alarm started" kill $ALARM_PID 2>/dev/null play -loop 0 $SOUNDS/alarm_simple.ogg & ALARM_PID=$! } function pa-alarm-stop() { info "Alarm stopped" 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 } function pa-say() { info "Say: $@" cat /dev/null | $SPEAK "$@" }