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:
@@ -6,6 +6,8 @@ import os
|
|||||||
import sqlite3
|
import sqlite3
|
||||||
import subprocess
|
import subprocess
|
||||||
import tempfile
|
import tempfile
|
||||||
|
import io
|
||||||
|
import soundfile
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
@@ -169,15 +171,22 @@ def bird_weather(file: ParseFileName, detections: [Detection]):
|
|||||||
if conf['BIRDWEATHER_ID'] == "":
|
if conf['BIRDWEATHER_ID'] == "":
|
||||||
return
|
return
|
||||||
if detections:
|
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
|
# POST soundscape to server
|
||||||
soundscape_url = (f'https://app.birdweather.com/api/v1/stations/'
|
soundscape_url = (f'https://app.birdweather.com/api/v1/stations/'
|
||||||
f'{conf["BIRDWEATHER_ID"]}/soundscapes?timestamp={file.iso8601}')
|
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:
|
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'})
|
headers={'Content-Type': 'application/octet-stream', 'Content-Encoding': 'gzip'})
|
||||||
log.info("Soundscape POST Response Status - %d", response.status_code)
|
log.info("Soundscape POST Response Status - %d", response.status_code)
|
||||||
sdata = response.json()
|
sdata = response.json()
|
||||||
|
|||||||
Reference in New Issue
Block a user