Skip to content

A live bird collage card for your Home Assistant dashboard.

adding choice for audio format changed default format to mp3 sox now handles extraction (instead of ffmpeg)

mcguirepr892c1216aeae8e
diff --git a/birdnet.conf-defaults b/birdnet.conf-defaults
index 20504b07..0513576a 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 03d41036..d2c8b012 100644
--- a/homepage/top.html
+++ b/homepage/top.html
@@ -43,6 +43,7 @@ footer {
<p style="margin:0;padding-left:150px;padding-top:5px">
<a href="/overview.php" target="content">Overview</a> |
<a href="/viewdb.php" target="content">Database</a> |
+ <a href="/stats.php" target="content">Species Stats</a> |
<a href="/viewday.php" target="content">Today</a> |
<a href="/spectrogram.php" target="content">Spectrogram</a>
</p>
diff --git a/scripts/advanced.php b/scripts/advanced.php
index fd225932..774ad3b9 100644
--- a/scripts/advanced.php
+++ b/scripts/advanced.php
@@ -1,12 +1,12 @@
<?php
+ini_set('display_errors', 1);
+ini_set('display_startup_errors', 1);
+error_reporting(E_ALL);
if (file_exists('/home/pi/BirdNET-Pi/thisrun.txt')) {
$config = parse_ini_file('/home/pi/BirdNET-Pi/thisrun.txt');
} elseif (file_exists('/home/pi/BirdNET-Pi/firstrun.ini')) {
$config = parse_ini_file('/home/pi/BirdNET-Pi/firstrun.ini');
}
-ini_set('display_errors', 1);
-ini_set('display_startup_errors', 1);
-error_reporting(E_ALL);
if(isset($_POST['submit'])) {
$contents = file_get_contents("/home/pi/BirdNET-Pi/birdnet.conf");
@@ -145,6 +145,14 @@ if(isset($_POST['submit'])) {
}
}
+ if(isset($_POST["audiofmt"])) {
+ $audiofmt = $_POST["audiofmt"];
+ if(strcmp($audiofmt,$config['AUDIOFMT']) !== 0) {
+ $contents = preg_replace("/AUDIOFMT=.*/", "AUDIOFMT=$audiofmt", $contents);
+ $contents2 = preg_replace("/AUDIOFMT=.*/", "AUDIOFMT=$audiofmt", $contents2);
+ }
+ }
+
$fh = fopen("/home/pi/BirdNET-Pi/birdnet.conf", "w");
$fh2 = fopen("/home/pi/BirdNET-Pi/thisrun.txt", "w");
fwrite($fh, $contents);
@@ -225,7 +233,7 @@ label {
width: 40%;
font-weight:bold;
}
-input {
+input,select {
width: 60%;
text-align:center;
font-size:large;
@@ -285,7 +293,17 @@ if (strcmp($newconfig['FULL_DISK'], "purge") == 0) {
<p>Set Recording Length in seconds between 6 and 60. Multiples of 3 are recommended, as BirdNET analyzes in 3-second chunks.</p>
<label for="extraction_length">Extraction Length: </label>
<input name="extraction_length" type="number" min="3" max="<?php print($newconfig['RECORDING_LENGTH']);?>" value="<?php print($newconfig['EXTRACTION_LENGTH']);?>" /><br>
- <p>Set Extraction Length to something less than your Recording Length. Min=3 Max=Recording Length
+ <p>Set Extraction Length to something less than your Recording Length. Min=3 Max=Recording Length</p>
+ <label for="audiofmt">Extractions Audio Format</label>
+ <select name="audiofmt">
+ <option selected="<?php print($newconfig['AUDIOFMT']);?>"><?php print($newconfig['AUDIOFMT']);?></option>
+<?php
+ $formats = array("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");
+foreach($formats as $format){
+ echo "<option value='$format'>$format</option>";
+}
+?>
+ </select>
<h3>Passwords</h3>
<label for="caddy_pwd">Webpage: </label>
<input name="caddy_pwd" type="text" value="<?php print($newconfig['CADDY_PWD']);?>" /><br>
@@ -321,12 +339,12 @@ if (strcmp($newconfig['FULL_DISK'], "purge") == 0) {
<br><br>
<button type="submit" name="submit" class="block"><?php
- if(isset($_SESSION['success'])){
- echo "Success!";
- unset($_SESSION['success']);
- } else {
- echo "Update Settings";
- }
+if(isset($_SESSION['success'])){
+ echo "Success!";
+ unset($_SESSION['success']);
+} else {
+ echo "Update Settings";
+}
?></button>
<br>
</form>
diff --git a/scripts/extract_new_birdsounds.sh b/scripts/extract_new_birdsounds.sh
index 80ec6857..1fac41e8 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}"