mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-05 18:55:23 +03:00
Add audio filters config
This commit is contained in:
parent
fbbd55149a
commit
a1d2f98765
@ -11,7 +11,13 @@ import numpy as np
|
|||||||
from pydantic import BaseModel, Extra, Field, parse_obj_as, validator
|
from pydantic import BaseModel, Extra, Field, parse_obj_as, validator
|
||||||
from pydantic.fields import PrivateAttr
|
from pydantic.fields import PrivateAttr
|
||||||
|
|
||||||
from frigate.const import CACHE_DIR, DEFAULT_DB_PATH, REGEX_CAMERA_NAME, YAML_EXT
|
from frigate.const import (
|
||||||
|
AUDIO_MIN_CONFIDENCE,
|
||||||
|
CACHE_DIR,
|
||||||
|
DEFAULT_DB_PATH,
|
||||||
|
REGEX_CAMERA_NAME,
|
||||||
|
YAML_EXT,
|
||||||
|
)
|
||||||
from frigate.detectors import DetectorConfig, ModelConfig
|
from frigate.detectors import DetectorConfig, ModelConfig
|
||||||
from frigate.detectors.detector_config import BaseDetectorConfig
|
from frigate.detectors.detector_config import BaseDetectorConfig
|
||||||
from frigate.ffmpeg_presets import (
|
from frigate.ffmpeg_presets import (
|
||||||
@ -334,6 +340,15 @@ class FilterConfig(FrigateBaseModel):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class AudioFilterConfig(FrigateBaseModel):
|
||||||
|
threshold: float = Field(
|
||||||
|
default=0.8,
|
||||||
|
ge=AUDIO_MIN_CONFIDENCE,
|
||||||
|
lt=1.0,
|
||||||
|
title="Minimum detection confidence threshold for audio to be counted.",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class RuntimeFilterConfig(FilterConfig):
|
class RuntimeFilterConfig(FilterConfig):
|
||||||
mask: Optional[np.ndarray]
|
mask: Optional[np.ndarray]
|
||||||
raw_mask: Optional[Union[str, List[str]]]
|
raw_mask: Optional[Union[str, List[str]]]
|
||||||
@ -424,6 +439,7 @@ class AudioConfig(FrigateBaseModel):
|
|||||||
listen: List[str] = Field(
|
listen: List[str] = Field(
|
||||||
default=DEFAULT_LISTEN_AUDIO, title="Audio to listen for."
|
default=DEFAULT_LISTEN_AUDIO, title="Audio to listen for."
|
||||||
)
|
)
|
||||||
|
filters: Optional[Dict[str, AudioFilterConfig]] = Field(title="Audio filters.")
|
||||||
enabled_in_config: Optional[bool] = Field(
|
enabled_in_config: Optional[bool] = Field(
|
||||||
title="Keep track of original state of audio detection."
|
title="Keep track of original state of audio detection."
|
||||||
)
|
)
|
||||||
|
|||||||
@ -28,6 +28,7 @@ AUDIO_DURATION = 0.975
|
|||||||
AUDIO_FORMAT = "s16le"
|
AUDIO_FORMAT = "s16le"
|
||||||
AUDIO_MAX_BIT_RANGE = 32768.0
|
AUDIO_MAX_BIT_RANGE = 32768.0
|
||||||
AUDIO_SAMPLE_RATE = 16000
|
AUDIO_SAMPLE_RATE = 16000
|
||||||
|
AUDIO_MIN_CONFIDENCE = 0.5
|
||||||
|
|
||||||
# Regex Consts
|
# Regex Consts
|
||||||
|
|
||||||
|
|||||||
@ -19,6 +19,7 @@ from frigate.const import (
|
|||||||
AUDIO_DURATION,
|
AUDIO_DURATION,
|
||||||
AUDIO_FORMAT,
|
AUDIO_FORMAT,
|
||||||
AUDIO_MAX_BIT_RANGE,
|
AUDIO_MAX_BIT_RANGE,
|
||||||
|
AUDIO_MIN_CONFIDENCE,
|
||||||
AUDIO_SAMPLE_RATE,
|
AUDIO_SAMPLE_RATE,
|
||||||
CACHE_DIR,
|
CACHE_DIR,
|
||||||
FRIGATE_LOCALHOST,
|
FRIGATE_LOCALHOST,
|
||||||
@ -130,7 +131,7 @@ class AudioTfl:
|
|||||||
|
|
||||||
return detections
|
return detections
|
||||||
|
|
||||||
def detect(self, tensor_input, threshold=0.8):
|
def detect(self, tensor_input, threshold=AUDIO_MIN_CONFIDENCE):
|
||||||
detections = []
|
detections = []
|
||||||
|
|
||||||
if self.stop_event.is_set():
|
if self.stop_event.is_set():
|
||||||
@ -200,7 +201,8 @@ class AudioEventMaintainer(threading.Thread):
|
|||||||
if label not in self.config.audio.listen:
|
if label not in self.config.audio.listen:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
self.handle_detection(label, score)
|
if score > self.config.audio.filters.get(label, {}).get("threshold", 0):
|
||||||
|
self.handle_detection(label, score)
|
||||||
|
|
||||||
self.expire_detections()
|
self.expire_detections()
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user