From 2c1216aeae8ea89062a2aa531c17d42c1bc7507a Mon Sep 17 00:00:00 2001
From: mcguirepr89
Date: Mon, 14 Feb 2022 13:43:12 -0500
Subject: [PATCH] adding choice for audio format changed default format to mp3
sox now handles extraction (instead of ffmpeg)
---
birdnet.conf-defaults | 14 ++++++++++-
homepage/top.html | 1 +
scripts/advanced.php | 40 ++++++++++++++++++++++---------
scripts/extract_new_birdsounds.sh | 20 +++++++---------
4 files changed, 51 insertions(+), 24 deletions(-)
diff --git a/birdnet.conf-defaults b/birdnet.conf-defaults
index 20504b0..0513576 100644
--- a/birdnet.conf-defaults
+++ b/birdnet.conf-defaults
@@ -155,7 +155,8 @@ FULL_DISK=purge
VENV=/home/pi/BirdNET-Pi/birdnet
-## RECORDING_LENGTH sets the length of the recording that BirdNET-Lite will analyze.
+## RECORDING_LENGTH sets the length of the recording that BirdNET-Lite will
+## analyze.
RECORDING_LENGTH=15
@@ -165,6 +166,17 @@ RECORDING_LENGTH=15
EXTRACTION_LENGTH=
+## AUDIOFMT set the audio format that sox should use for the extractions.
+## The default is mp3. Available formats are: 8svx aif aifc aiff aiffc al amb
+## amr-nb amr-wb anb au avr awb caf cdda cdr cvs cvsd cvu dat dvms f32 f4 f64 f8
+## fap flac fssd gsm gsrt hcom htk ima ircam la lpc lpc10 lu mat mat4 mat5 maud
+## mp2 mp3 nist ogg paf prc pvf raw s1 s16 s2 s24 s3 s32 s4 s8 sb sd2 sds sf sl
+## sln smp snd sndfile sndr sndt sou sox sph sw txw u1 u16 u2 u24 u3 u32 u4 u8
+## ub ul uw vms voc vorbis vox w64 wav wavpcm wv wve xa xi
+## Note: Most have not been tested.
+
+AUDIOFMT=mp3
+
## BIRDNET_USER should be the non-root user systemd should use to execute each
## service.
diff --git a/homepage/top.html b/homepage/top.html
index 03d4103..d2c8b01 100644
--- a/homepage/top.html
+++ b/homepage/top.html
@@ -43,6 +43,7 @@ footer {
diff --git a/scripts/advanced.php b/scripts/advanced.php
index fd22593..774ad3b 100644
--- a/scripts/advanced.php
+++ b/scripts/advanced.php
@@ -1,12 +1,12 @@
Set Recording Length in seconds between 6 and 60. Multiples of 3 are recommended, as BirdNET analyzes in 3-second chunks.
-
Set Extraction Length to something less than your Recording Length. Min=3 Max=Recording Length
+
Set Extraction Length to something less than your Recording Length. Min=3 Max=Recording Length
+
+
Passwords
@@ -321,12 +339,12 @@ if (strcmp($newconfig['FULL_DISK'], "purge") == 0) {
diff --git a/scripts/extract_new_birdsounds.sh b/scripts/extract_new_birdsounds.sh
index 80ec685..1fac41e 100755
--- a/scripts/extract_new_birdsounds.sh
+++ b/scripts/extract_new_birdsounds.sh
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
# Exit when any command fails
-#set -x
+set -x
set -e
# Keep track of the last executed command
#trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG
@@ -64,7 +64,8 @@ for h in "${SCAN_DIRS[@]}";do
| awk -F\; '{print $5}' \
| cut -d'.' -f2)""
CONFIDENCE_SCORE="${CONFIDENCE:0:2}%"
- NEWFILE="${COMMON_NAME// /_}-${CONFIDENCE_SCORE}-${OLDFILE}"
+ NEWFILE="${COMMON_NAME// /_}-${CONFIDENCE_SCORE}-${OLDFILE//.wav/.${AUDIOFMT}}"
+ echo "NEWFILE=$NEWFILE"
NEWSPECIES_BYDATE="${EXTRACTED}/By_Date/${DATE}/${COMMON_NAME// /_}"
NEWSPECIES_BY_COMMON="${EXTRACTED}/By_Common_Name/${COMMON_NAME// /_}"
NEWSPECIES_BY_SCIENCE="${EXTRACTED}/By_Scientific_Name/${SCIENTIFIC_NAME// /_}"
@@ -102,7 +103,6 @@ for h in "${SCAN_DIRS[@]}";do
# ls -1t . | tail -n +20 | xargs -r rm -vv
# fi
- echo "Extracting audio . . . "
# If the above tests have passed, then the extraction happens.
# After creating the extracted files by-date, and a directory tree
# structured by-species, symbolic links are made to populate the new
@@ -129,9 +129,11 @@ for h in "${SCAN_DIRS[@]}";do
END=${RECORDING_LENGTH}
fi
- ffmpeg -hide_banner -loglevel error -nostdin -i "${h}/${OLDFILE}" \
- -acodec copy -ss "${START}" -to "${END}"\
- "${NEWSPECIES_BYDATE}/${NEWFILE}"
+ sox "${h}/${OLDFILE}" "${NEWSPECIES_BYDATE}/${NEWFILE}" \
+ trim "${START}" "${END}"
+ #ffmpeg -hide_banner -loglevel error -nostdin -i "${h}/${OLDFILE}" \
+ # -acodec copy -ss "${START}" -to "${END}"\
+ # "${NEWSPECIES_BYDATE}/${NEWFILE}"
# Create spectrogram for extraction
sox "${NEWSPECIES_BYDATE}/${NEWFILE}" -n remix 1 rate 24k spectrogram \
@@ -183,7 +185,6 @@ for h in "${SCAN_DIRS[@]}";do
done < "${TMPFILE}"
- echo -e "\n\n\nFINISHED!!! Processed extractions for ${h:19}"
# Once each line of the TMPFILE has been processed, the TMPFILE is emptied
# for the next iteration of the for loop.
>"${TMPFILE}"
@@ -201,8 +202,3 @@ echo "Linking Processed files to "${EXTRACTED}/Processed" web directory"
if [[ ! -L ${EXTRACTED}/Processed ]] || [[ ! -e ${EXTRACTED}/Processed ]];then
ln -sf ${PROCESSED} ${EXTRACTED}/Processed
fi
-
-
-
-# That's all!
-echo "Finished -- the extracted sections are in ${EXTRACTED}"