From 0cf4c4890d64873073c8649ed267fa9f20ed6b96 Mon Sep 17 00:00:00 2001 From: Dejvino Date: Sat, 9 Jan 2021 14:22:58 +0100 Subject: [PATCH] Add continuous announcement server. --- bin/announcement-server | 21 +++++++++++++++++++++ bin/pa-lib | 25 ++++++++++++++++++++----- 2 files changed, 41 insertions(+), 5 deletions(-) create mode 100755 bin/announcement-server diff --git a/bin/announcement-server b/bin/announcement-server new file mode 100755 index 0000000..6c8a6be --- /dev/null +++ b/bin/announcement-server @@ -0,0 +1,21 @@ +#!/bin/bash + +source pa-lib + +while [[ true ]]; do + # waiting for the PSA text stream to start + read + + pa-preheat + pa-announcement + pa-say "$REPLY" + while read -t 4; do + pa-say "$REPLY" + done + + # no more text, terminate the PSA + pa-announcement-quick + pa-shutdown +done + + diff --git a/bin/pa-lib b/bin/pa-lib index 9f36201..1dac55c 100644 --- a/bin/pa-lib +++ b/bin/pa-lib @@ -7,12 +7,15 @@ export SOUNDS=$ROOT/sounds export PLAYER=mplayer export SPEAK=espeak-ng +ALARM_PID=-1 +STATIC_PID=-1 + function info() { echo "[INFO]" $@ } function play() { - $PLAYER $@ > /dev/null 2>&1 + cat /dev/null | $PLAYER $@ > /dev/null 2>&1 } function pa-volume() { @@ -49,7 +52,8 @@ function pa-preheat() { info "PA Preheating" pa-power off pa-volume-normal - play $SOUNDS/announcement_4-tone_up_quickest.ogg + pa-static-start 40 + play $SOUNDS/announcement_4-tone_up_quick.ogg pa-power on info "PA Ready" } @@ -58,7 +62,7 @@ function pa-shutdown() { info "PA Shutdown" pa-power off pa-volume-normal - killall $PLAYER + killall $PLAYER >/dev/null 2>&1 } function pa-announcement() { @@ -78,17 +82,28 @@ function pa-announcement-quickest() { 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" - killall $PLAYER + 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: $@" - $SPEAK "$@" + cat /dev/null | $SPEAK "$@" }