Save audio scores and add audio filter config (#7185)

* Send and save score for external events

* Add audio filters config

* Fix access

* Add docs

* Cleanup
This commit is contained in:
Nicolas Mowen
2023-07-17 05:07:15 -06:00
committed by GitHub
parent dacf45cd88
commit c5b8d13beb
7 changed files with 39 additions and 5 deletions

View File

@@ -19,6 +19,7 @@ from frigate.const import (
AUDIO_DURATION,
AUDIO_FORMAT,
AUDIO_MAX_BIT_RANGE,
AUDIO_MIN_CONFIDENCE,
AUDIO_SAMPLE_RATE,
CACHE_DIR,
FRIGATE_LOCALHOST,
@@ -130,7 +131,7 @@ class AudioTfl:
return detections
def detect(self, tensor_input, threshold=0.8):
def detect(self, tensor_input, threshold=AUDIO_MIN_CONFIDENCE):
detections = []
if self.stop_event.is_set():
@@ -200,7 +201,10 @@ class AudioEventMaintainer(threading.Thread):
if label not in self.config.audio.listen:
continue
self.handle_detection(label, score)
if score > (self.config.audio.filters or {}).get(label, {}).get(
"threshold", 0.8
):
self.handle_detection(label, score)
self.expire_detections()
@@ -233,7 +237,7 @@ class AudioEventMaintainer(threading.Thread):
resp = requests.post(
f"{FRIGATE_LOCALHOST}/api/events/{self.config.name}/{label}/create",
json={"duration": None, "source_type": "audio"},
json={"duration": None, "score": score, "source_type": "audio"},
)
if resp.status_code == 200:

View File

@@ -31,6 +31,7 @@ class ExternalEventProcessor:
label: str,
source_type: str,
sub_label: Optional[str],
score: int,
duration: Optional[int],
include_recording: bool,
draw: dict[str, any],
@@ -56,6 +57,7 @@ class ExternalEventProcessor:
"id": event_id,
"label": label,
"sub_label": sub_label,
"score": score,
"camera": camera,
"start_time": now - camera_config.record.events.pre_capture,
"end_time": now

View File

@@ -230,7 +230,11 @@ class EventProcessor(threading.Thread):
Event.has_clip: event_data["has_clip"],
Event.has_snapshot: event_data["has_snapshot"],
Event.zones: [],
Event.data: {"type": event_data["type"]},
Event.data: {
"type": event_data["type"],
"score": event_data["score"],
"top_score": event_data["score"],
},
}
Event.insert(event).execute()
elif event_type == "end":