extraction service working

This commit is contained in:
Patrick McGuire
2021-09-28 18:29:14 -04:00
parent 7780b645a6
commit 7cb436796a
3 changed files with 35 additions and 36 deletions
+10 -9
View File
@@ -46,16 +46,17 @@ run_analysis() {
echo "Starting run_analysis() for ${1}" echo "Starting run_analysis() for ${1}"
WEEK=$(date --date="${2}" +"%U") WEEK=$(date --date="${2}" +"%U")
cd ${HOME}/BirdNET-Lite || exit 1 cd ${HOME}/BirdNET-Lite || exit 1
FILES=("$(find ${1} | tail -n+2)")
for i in "${files[@]}";do for i in "${files[@]}";do
python3 analyze.py \ if [ -f ${1}/${i} ];then
--i "${1}/${i}" \ python3 analyze.py \
--o "${1}/${i}.csv" \ --i "${1}/${i}" \
--lat "${LATITUDE}" \ --o "${1}/${i}.csv" \
--lon "${LONGITUDE}" \ --lat "${LATITUDE}" \
--week "${WEEK}" \ --lon "${LONGITUDE}" \
--overlap "${OVERLAP}" \ --week "${WEEK}" \
--min_conf "${CONFIDENCE}" --overlap "${OVERLAP}" \
--min_conf "${CONFIDENCE}"
fi
done done
} }
+2 -2
View File
@@ -6,10 +6,10 @@ if pgrep arecord &> /dev/null ;then
echo "Recording" echo "Recording"
else else
if [ -z ${REC_CARD} ];then if [ -z ${REC_CARD} ];then
arecord -f S16_LE -c${CHANNELS} -r48000 -t wav --max-file-time 25\ arecord -f S16_LE -c${CHANNELS} -r48000 -t wav --max-file-time 10\
--use-strftime ${RECS_DIR}/%B-%Y/%d-%A/%F-birdnet-%I:%M:%S%P.wav --use-strftime ${RECS_DIR}/%B-%Y/%d-%A/%F-birdnet-%I:%M:%S%P.wav
else else
arecord -f S16_LE -c${CHANNELS} -r48000 -t wav --max-file-time 25\ arecord -f S16_LE -c${CHANNELS} -r48000 -t wav --max-file-time 10\
-D "${REC_CARD}" --use-strftime \ -D "${REC_CARD}" --use-strftime \
${RECS_DIR}/%B-%Y/%d-%A/%F-birdnet-%I:%M:%S%P.wav ${RECS_DIR}/%B-%Y/%d-%A/%F-birdnet-%I:%M:%S%P.wav
fi fi
+23 -25
View File
@@ -35,20 +35,19 @@ echo "Starting numbering at ${a}"
for h in "${SCAN_DIRS[@]}";do for h in "${SCAN_DIRS[@]}";do
echo "Creating the TMPFILE" echo "Creating the TMPFILE"
# The TMPFILE is created from each "Selection" txt file BirdNET creates # The TMPFILE is created from each .csv file BirdNET creates
# within each "Analyzed" directory # within each "Analyzed" directory
# Field 1: Original WAVE file name # Field 1: Start (s)
# Field 2: Extraction start time in seconds # Field 2: End (s)
# Field 3: Extraction end time in seconds # Field 3: Scientific name
# Field 4: New WAVE file name to use # Field 4: Common name
# Field 5: The species name # Field 5: Confidence
# Iterates over each "Analyzed" directory # Iterates over each "Analyzed" directory
for i in $(find ${h} -name '*txt' | sort );do for i in $(find ${h} -name '*csv' | sort );do
# Iterates over each '.txt' file found in each "Analyzed" directory # Iterates over each '.csv' file found in each "Analyzed" directory
# to create the TMPFILE # to create the TMPFILE
sort -k 6n "$i" \ echo "${i}" | cut -d'/' -f7 >> ${TMPFILE}
| awk '/Spect/ {print}' \ sort -k1n -t\; "${i}" | awk '!/Start/{print}' >> ${TMPFILE}
>> $TMPFILE
done done
# The extraction reads each line of the TMPFILE and sets the variables ffmpeg # The extraction reads each line of the TMPFILE and sets the variables ffmpeg
@@ -56,18 +55,17 @@ for h in "${SCAN_DIRS[@]}";do
while read -r line;do while read -r line;do
a=$a a=$a
DATE="$(echo "${line}" \ DATE="$(echo "${line}" \
| awk '{print $5}' \ | awk -F- '/birdnet/{print $1"-"$2"-"$3}')"
| awk -F- '{print $1"-"$2"-"$3}')" if [ ! -z ${DATE} ];then
OLDFILE="$(echo "${line}" | awk '{print $5}')" OLDFILE="$(echo "${line}" | awk -F. '/birdnet/{print $1"."$2}')" ; continue
START="$(echo "${line}" | awk '{print $6}')" fi
END="$(echo "${line}" | awk '{print $7}')" START="$(echo "${line}" | awk -F\; '!/birdnet/{print $1}')"
SPECIES=""$(echo ${line//\'} \ END="$(echo "${line}" | awk -F\; '!/birdnet/{print $2}')"
| awk '{for(i=11;i<=NF;++i)printf $i""FS ; print ""}' \ COMMON_NAME=""$(echo ${line} \
| cut -d'0' -f1 \ | awk -F\; '!/birdnet/{print $3}')""
| xargs)"" NEWFILE="${COMMON_NAME// /_}-${OLDFILE}"
NEWFILE="${SPECIES// /_}-${OLDFILE}" NEWSPECIES_BYDATE="${EXTRACTED}/By_Date/${DATE}/${COMMON_NAME// /_}"
NEWSPECIES_BYDATE="${EXTRACTED}/By_Date/${DATE}/${SPECIES// /_}" NEWSPECIES_BYSPEC="${EXTRACTED}/By_Species/${COMMON_NAME// /_}"
NEWSPECIES_BYSPEC="${EXTRACTED}/By_Species/${SPECIES// /_}"
# If the extracted file already exists, increment the 'a' variable once # If the extracted file already exists, increment the 'a' variable once
# but move onto the next line of the TMPFILE for extraction. # but move onto the next line of the TMPFILE for extraction.
@@ -110,7 +108,7 @@ for h in "${SCAN_DIRS[@]}";do
# structured by-species, symbolic links are made to populate the new # structured by-species, symbolic links are made to populate the new
# directory. # directory.
ffmpeg -hide_banner -loglevel error -nostdin -i "${h}/${OLDFILE}" \ ffmpeg -hide_banner -loglevel 52 -nostdin -i "${h}/${OLDFILE}" \
-acodec copy -ss "${START}" -to "${END}"\ -acodec copy -ss "${START}" -to "${END}"\
"${NEWSPECIES_BYDATE}/${a}-${NEWFILE}" "${NEWSPECIES_BYDATE}/${a}-${NEWFILE}"
if [[ "$(find ${NEWSPECIES_BYSPEC} | wc -l)" -ge 21 ]];then if [[ "$(find ${NEWSPECIES_BYSPEC} | wc -l)" -ge 21 ]];then
@@ -119,7 +117,7 @@ for h in "${SCAN_DIRS[@]}";do
ls -1t . | tail -n +21 | xargs -r rm -vv ls -1t . | tail -n +21 | xargs -r rm -vv
ln -fs "${NEWSPECIES_BYDATE}/${a}-${NEWFILE}"\ ln -fs "${NEWSPECIES_BYDATE}/${a}-${NEWFILE}"\
"${NEWSPECIES_BYSPEC}/${a}-${NEWFILE}" "${NEWSPECIES_BYSPEC}/${a}-${NEWFILE}"
echo "Success! New extraction for ${SPECIES}" echo "Success! New extraction for ${COMMON_NAME}"
else else
ln -fs "${NEWSPECIES_BYDATE}/${a}-${NEWFILE}"\ ln -fs "${NEWSPECIES_BYDATE}/${a}-${NEWFILE}"\
"${NEWSPECIES_BYSPEC}/${a}-${NEWFILE}" "${NEWSPECIES_BYSPEC}/${a}-${NEWFILE}"