r/BirdNET_Analyzer • u/dacracot • Apr 27 '22
Software Gathering and analyzing with two bash scripts.
Both scripts are run by the crontab.
The first script, called beforeDawn.sh, is run at 4:00am...
#!/bin/bash
export YEAR=`date '+%Y'`
export MONTH=`date '+%m'`
export DAY=`date '+%d'`
mkdir -p /home/tweet/samples/${YEAR}/${MONTH}/${DAY}/
arecord -D sysdefault:CARD=2 --quiet --max-file-time 60 -f S16_LE -r 48000 -t wav --use-strftime /home/tweet/samples/%Y/%m/%d/%H-%M-%S.wav &
echo "$!" > recording.pid
The second script, called afterDark.sh, is run at 8:30pm...
#!/bin/bash
TIMEFORMAT='Elapsed Time: %0R seconds.'
time {
export YEAR=`date '+%Y'`
export MONTH=`date '+%m'`
export DAY=`date '+%d'`
export WEEK=`date '+%U'`
kill `cat /home/tweet/recording.pid`
for f in `ls /home/tweet/samples/${YEAR}/${MONTH}/${DAY}/*.wav`
do
python3 /home/tweet/BirdNET-Analyzer/analyze.py --i ${f} --o ${f%.wav}.csv --rtype csv --min_conf 0.6 --threads 3 --lat 23.8 --lon -81.0 --week ${WEEK} --slist /home/tweet/samples/species_list.txt >> /home/tweet/${YEAR}-${MONTH}-${DAY}.out 2>> /home/tweet/${YEAR}-${MONTH}-${DAY}.err
t=$(basename ${f})
# add the file name (a timestamp) to the end of each file row
sed -i 's/$/,'"${t%.wav}"'/' ${f%.wav}.csv
done
cat /home/tweet/header.csv > ${YEAR}-${MONTH}-${DAY}.csv
# strip the headers
cat /home/tweet/samples/${YEAR}/${MONTH}/${DAY}/*.csv | grep -v Confidence >> /home/tweet/t1.csv
# sort by common name and confidence
sort -t "," -k3,3 -k5,5nr /home/tweet/t1.csv > /home/tweet/t2.csv
# remove the first few columns
cut -d ',' -f 4,5- t2.csv >> /home/tweet/${YEAR}-${MONTH}-${DAY}.csv
# clean up
rm /home/tweet/t*.csv
gzip /home/tweet/${YEAR}-${MONTH}-${DAY}.err
gzip /home/tweet/${YEAR}-${MONTH}-${DAY}.out
gzip /home/tweet/samples/${YEAR}/${MONTH}/${DAY}/*
}