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
This commit is contained in:
Alexandre
2025-08-02 13:08:41 +02:00
committed by GitHub
parent 943e1ab9dd
commit 6572aa22b2
+13 -4
View File
@@ -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()