From 387d7fa7006ee18b6489b802d83d6dddfa7649c9 Mon Sep 17 00:00:00 2001 From: frederik Date: Wed, 3 Jan 2024 13:50:00 +0100 Subject: [PATCH] use inotifywait --- scripts/spectrogram.sh | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/scripts/spectrogram.sh b/scripts/spectrogram.sh index fe5ec7a..b3aa37a 100755 --- a/scripts/spectrogram.sh +++ b/scripts/spectrogram.sh @@ -12,18 +12,13 @@ if [ "$LOGGING_LEVEL" == "info" ] || [ "$LOGGING_LEVEL" == "debug" ];then set -x 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 +inotifywait -m -e close_write "$HOME/BirdNET-Pi/analyzing_now.txt" | +while read; do + analyzing_now="$(<$HOME/BirdNET-Pi/analyzing_now.txt)" -# 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 + if [ -n "${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