Skip to content

A live bird collage card for your Home Assistant dashboard.

enables raw/minimalist spectograms (#471)

John McClumphaadef45f74116
diff --git a/scripts/spectrogram.sh b/scripts/spectrogram.sh
index 60fffee2..73cfcf65 100755
--- a/scripts/spectrogram.sh
+++ b/scripts/spectrogram.sh
@@ -25,7 +25,13 @@ while read; do
if [ -n "${analyzing_now}" ] && [ -f "${analyzing_now}" ]; then
spectrogram_png=${EXTRACTED}/spectrogram.png
- sox -V1 "${analyzing_now}" -n remix 1 rate 24k spectrogram -c "${analyzing_now//$HOME\//}" -o "${spectrogram_png}"
+ # 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 "${analyzing_now}" -n remix 1 rate 24k spectrogram -c "${analyzing_now//$HOME\//}" -o "${spectrogram_png}" -r
+ else
+ sox -V1 "${analyzing_now}" -n remix 1 rate 24k spectrogram -c "${analyzing_now//$HOME\//}" -o "${spectrogram_png}"
+ fi
fi
next=$(( now + looptime ))
fi
diff --git a/scripts/utils/reporting.py b/scripts/utils/reporting.py
index c8c5f62c..171f90f6 100644
--- a/scripts/utils/reporting.py
+++ b/scripts/utils/reporting.py
@@ -45,12 +45,13 @@ def extract_safe(in_file, out_file, start, stop):
extract(in_file, out_file, safe_start, safe_stop)
-def spectrogram(in_file, title, comment, raw=False):
+def spectrogram(in_file, title, comment, raw=0):
fd, tmp_file = tempfile.mkstemp(suffix='.png')
os.close(fd)
args = ['sox', '-V1', f'{in_file}', '-n', 'remix', '1', 'rate', '24k', 'spectrogram',
'-t', '', '-c', '', '-o', tmp_file]
- args += ['-r'] if raw else []
+ args += ['-r'] if int(raw) else []
+
result = subprocess.run(args, check=True, capture_output=True)
ret = result.stdout.decode('utf-8')
err = result.stderr.decode('utf-8')
@@ -81,7 +82,7 @@ def extract_detection(file: ParseFileName, detection: Detection):
else:
os.makedirs(new_dir, exist_ok=True)
extract_safe(file.file_name, new_file, detection.start, detection.stop)
- spectrogram(new_file, detection.common_name, new_file.replace(os.path.expanduser('~/'), ''))
+ spectrogram(new_file, detection.common_name, new_file.replace(os.path.expanduser('~/'), ''), conf['RAW_SPECTROGRAM'])
return new_file