From 6572aa22b2fbe961b331da440f7126d56fd7cd51 Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Sat, 2 Aug 2025 13:08:41 +0200 Subject: [PATCH] Convert birdweather uploads to flac (#393) * Convert birdweather updates to flac https://github.com/Nachtzuster/BirdNET-Pi/discussions/390 * Remove wav zip @mikeporterinmd * Send raw flac * Restore gzip encoding --- scripts/utils/reporting.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/scripts/utils/reporting.py b/scripts/utils/reporting.py index 5763d39..336010b 100644 --- a/scripts/utils/reporting.py +++ b/scripts/utils/reporting.py @@ -6,6 +6,8 @@ import os import sqlite3 import subprocess import tempfile +import io +import soundfile from time import sleep import requests @@ -169,15 +171,22 @@ def bird_weather(file: ParseFileName, detections: [Detection]): if conf['BIRDWEATHER_ID'] == "": return if detections: + try: + data, samplerate = soundfile.read(file.file_name) + buf = io.BytesIO() + soundfile.write(buf, data, samplerate, format='FLAC') + flac_data = buf.getvalue() + except Exception as e: + log.error("Error during FLAC conversion: %s", e) + return + gzip_flac_data = gzip.compress(flac_data) + # POST soundscape to server soundscape_url = (f'https://app.birdweather.com/api/v1/stations/' f'{conf["BIRDWEATHER_ID"]}/soundscapes?timestamp={file.iso8601}') - with open(file.file_name, 'rb') as f: - wav_data = f.read() - gzip_wav_data = gzip.compress(wav_data) try: - response = requests.post(url=soundscape_url, data=gzip_wav_data, timeout=30, + response = requests.post(url=soundscape_url, data=gzip_flac_data, timeout=30, headers={'Content-Type': 'application/octet-stream', 'Content-Encoding': 'gzip'}) log.info("Soundscape POST Response Status - %d", response.status_code) sdata = response.json()