Adding support to create minimalist raw spectrogram images

This commit is contained in:
ehpersonal38
2023-03-06 16:26:29 -05:00
parent 19c4f3d6aa
commit adefbadb5f
5 changed files with 44 additions and 5 deletions
+5
View File
@@ -195,6 +195,11 @@ DATABASE_LANG=en
SILENCE_UPDATE_INDICATOR=0
## RAW_SPECTROGRAM is for removing the axes and labels of the spectrograms
## that are generated by Sox for each detection for a cleaner appearance.
RAW_SPECTROGRAM=0
## HEARTBEAT_URL is a location to ping every time some analysis is done
## no information is sent to the the URL, it is a heart beat to show that the
## analysis is continuing
+14
View File
@@ -200,6 +200,17 @@ if(isset($_GET['submit'])) {
$contents2 = preg_replace("/SILENCE_UPDATE_INDICATOR=.*/", "SILENCE_UPDATE_INDICATOR=0", $contents2);
}
if(isset($_GET["raw_spectrogram"])) {
$raw_spectrogram = 1;
if(strcmp($RAW_SPECTROGRAM,$config['RAW_SPECTROGRAM']) !== 0) {
$contents = preg_replace("/RAW_SPECTROGRAM=.*/", "RAW_SPECTROGRAM=$raw_spectrogram", $contents);
$contents2 = preg_replace("/RAW_SPECTROGRAM=.*/", "RAW_SPECTROGRAM=$raw_spectrogram", $contents2);
}
} else {
$contents = preg_replace("/RAW_SPECTROGRAM=.*/", "RAW_SPECTROGRAM=0", $contents);
$contents2 = preg_replace("/RAW_SPECTROGRAM=.*/", "RAW_SPECTROGRAM=0", $contents2);
}
$fh = fopen('/etc/birdnet/birdnet.conf', "w");
$fh2 = fopen("./scripts/thisrun.txt", "w");
fwrite($fh, $contents);
@@ -287,6 +298,9 @@ foreach($formats as $format){
<label for="silence_update_indicator">Silence Update Indicator: </label>
<input type="checkbox" name="silence_update_indicator" <?php if($newconfig['SILENCE_UPDATE_INDICATOR'] == 1) { echo "checked"; };?> ><br>
<label for="raw_spectrogram">Silence Update Indicator: </label>
<input type="checkbox" name="raw_spectrogram" <?php if($newconfig['RAW_SPECTROGRAM'] == 1) { echo "checked"; };?> ><br>
<h3>BirdNET-Lite Settings</h3>
<p>
+12 -1
View File
@@ -118,11 +118,22 @@ for h in "${SCAN_DIRS[@]}";do
sox -V1 "${h}/${OLDFILE}" "${NEWSPECIES_BYDATE}/${NEWFILE}" \
trim ="${START}" ="${END}"
# Create spectrogram for extraction
RAW_SPECTROGRAM=${RAW_SPECTROGRAM}
# Check if RAW_SPECTROGRAM is 1
if [ "$RAW_SPECTROGRAM" == "1" ]; then
# If it is, add "-r" as an argument to the SOX command
sox -V1 "${NEWSPECIES_BYDATE}/${NEWFILE}" -n remix 1 rate 24k spectrogram \
-t "${COMMON_NAME}" \
-c "${NEWSPECIES_BYDATE//$HOME\/}/${NEWFILE}" \
-o "${NEWSPECIES_BYDATE}/${NEWFILE}.png" \
-r
else
# If it's not, run the SOX command without the "-r" argument
sox -V1 "${NEWSPECIES_BYDATE}/${NEWFILE}" -n remix 1 rate 24k spectrogram \
-t "${COMMON_NAME}" \
-c "${NEWSPECIES_BYDATE//$HOME\/}/${NEWFILE}" \
-o "${NEWSPECIES_BYDATE}/${NEWFILE}.png"
fi
done < "${TMPFILE}"
+5
View File
@@ -228,6 +228,11 @@ HEARTBEAT_URL=
SILENCE_UPDATE_INDICATOR=0
## RAW_SPECTROGRAM is for removing the axes and labels of the spectrograms
## that are generated by Sox for each detection for a cleaner appearance.
RAW_SPECTROGRAM=0
## These are just for debugging
LAST_RUN=
THIS_RUN=
+4
View File
@@ -168,5 +168,9 @@ if ! grep -q 'RuntimeMaxSec=' "$HOME/BirdNET-Pi/templates/birdnet_analysis.servi
sudo systemctl daemon-reload && restart_services.sh
fi
if ! grep RAW_SPECTROGRAM /etc/birdnet/birdnet.conf &>/dev/null;then
sudo -u$USER echo "RAW_SPECTROGRAM=0" >> /etc/birdnet/birdnet.conf
fi
sudo systemctl daemon-reload
restart_services.sh