From 9a97d16883f43b75fd550bd2b17f39617d522131 Mon Sep 17 00:00:00 2001 From: jaredb7 Date: Sun, 9 Apr 2023 22:49:53 +1000 Subject: [PATCH] Make the Spectrogram service run as a loop The Spectrogram service was stopping after it completed it's work (no issue here) and the system would start it again 10 seconds later, sometimes it would stop and start multiple times a second (no file to analyse maybe) Added a while loop to that it would just keep running and sleeping for the number of seconds of the recording length setting. --- scripts/spectrogram.sh | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/scripts/spectrogram.sh b/scripts/spectrogram.sh index 03f299b..9e96bc1 100755 --- a/scripts/spectrogram.sh +++ b/scripts/spectrogram.sh @@ -1,8 +1,20 @@ #!/usr/bin/env bash +# set -x # Make sox spectrogram source /etc/birdnet/birdnet.conf -analyzing_now="$(cat $HOME/BirdNET-Pi/analyzing_now.txt)" -if [ ! -z "${analyzing_now}" ] && [ -f "${analyzing_now}" ]; then - spectrogram_png=${EXTRACTED}/spectrogram.png - sox -V1 "${analyzing_now}" -n remix 1 rate 24k spectrogram -c "${analyzing_now//$HOME\/}" -o "${spectrogram_png}" -fi + +# Time to sleep between generating spectrogram's, default set the recording length +# To try catch the spectrogram as soon as possible run at a smaller intervals +SLEEP_DELAY=$((RECORDING_LENGTH / 4)) + +# Continuously loop generating a spectrogram every 10 seconds +while true; do + analyzing_now="$(cat $HOME/BirdNET-Pi/analyzing_now.txt)" + + if [ ! -z "${analyzing_now}" ] && [ -f "${analyzing_now}" ]; then + spectrogram_png=${EXTRACTED}/spectrogram.png + sox -V1 "${analyzing_now}" -n remix 1 rate 24k spectrogram -c "${analyzing_now//$HOME\//}" -o "${spectrogram_png}" + fi + + sleep $SLEEP_DELAY +done