diff --git a/frigate/app.py b/frigate/app.py index fec751939..9d85f461e 100644 --- a/frigate/app.py +++ b/frigate/app.py @@ -21,7 +21,6 @@ from frigate.comms.mqtt import MqttClient from frigate.comms.ws import WebSocketClient from frigate.config import FrigateConfig from frigate.const import ( - AUDIO_DETECTOR, CACHE_DIR, CLIPS_DIR, CONFIG_DIR, @@ -30,8 +29,6 @@ from frigate.const import ( MODEL_CACHE_DIR, RECORD_DIR, ) -from frigate.detectors.plugins.audio_tfl import AudioDetectorConfig -from frigate.events.audio import AudioDetectProcess from frigate.events.cleanup import EventCleanup from frigate.events.external import ExternalEventProcessor from frigate.events.maintainer import EventProcessor @@ -62,7 +59,6 @@ class FrigateApp: self.detectors: dict[str, ObjectDetectProcess] = {} self.detection_out_events: dict[str, MpEvent] = {} self.detection_shms: list[mp.shared_memory.SharedMemory] = [] - self.audio_queue: Queue = mp.Queue() self.log_queue: Queue = mp.Queue() self.plus_api = PlusApi() self.camera_metrics: dict[str, CameraMetricsTypes] = {} @@ -290,8 +286,6 @@ class FrigateApp: ) def start_detectors(self) -> None: - audio_enabled = any(c.audio.enabled for c in self.config.cameras.items()) - for name in self.config.cameras.keys(): self.detection_out_events[name] = mp.Event() @@ -320,33 +314,6 @@ class FrigateApp: self.detection_shms.append(shm_in) self.detection_shms.append(shm_out) - - if audio_enabled: - try: - shm_in_audio = mp.shared_memory.SharedMemory( - name=f"{name}-audio", - create=True, - size=int( - round( - self.config.audio_model.duration - * self.config.audio_model.sample_rate - ) - ) - * 4, # stored as float32, so 4 bytes per sample - ) - except FileExistsError: - shm_in_audio = mp.shared_memory.SharedMemory(name=f"{name}-audio") - - try: - shm_out_audio = mp.shared_memory.SharedMemory( - name=f"out-{name}-audio", create=True, size=20 * 6 * 4 - ) - except FileExistsError: - shm_out_audio = mp.shared_memory.SharedMemory( - name=f"out-{name}-audio" - ) - - for name, detector_config in self.config.detectors.items(): self.detectors[name] = ObjectDetectProcess( name, @@ -355,14 +322,6 @@ class FrigateApp: detector_config, ) - if audio_enabled: - self.detectors[AUDIO_DETECTOR] = AudioDetectProcess( - AUDIO_DETECTOR, - self.audio_queue, - self.detection_out_events, - AudioDetectorConfig - ) - def start_detected_frames_processor(self) -> None: self.detected_frames_processor = TrackedObjectProcessor( self.config, diff --git a/frigate/const.py b/frigate/const.py index 987f04b46..9ebe6b573 100644 --- a/frigate/const.py +++ b/frigate/const.py @@ -15,6 +15,9 @@ BTBN_PATH = "/usr/lib/btbn-ffmpeg" # Audio Consts AUDIO_DETECTOR = "audio-detector" +AUDIO_DURATION = 0.975 +AUDIO_FORMAT = "s16le" +AUDIO_SAMPLE_RATE = 16000 # Regex Consts diff --git a/frigate/events/audio.py b/frigate/events/audio.py index 43dac978e..e92288a99 100644 --- a/frigate/events/audio.py +++ b/frigate/events/audio.py @@ -10,12 +10,20 @@ from typing import Optional from setproctitle import setproctitle from frigate.config import AudioConfig, CameraConfig, FrigateConfig -from frigate.const import CACHE_DIR +from frigate.const import ( + AUDIO_DETECTOR, + AUDIO_DURATION, + AUDIO_FORMAT, + AUDIO_SAMPLE_RATE, + CACHE_DIR, +) from frigate.util import listen logger = logging.getLogger(__name__) -FFMPEG_COMMAND = "ffmpeg -vn -i {} -f s16le -ar 16000 -ac 1 -y {}" +FFMPEG_COMMAND = ( + f"ffmpeg -vn -i {{}} -f {AUDIO_FORMAT} -ar {AUDIO_SAMPLE_RATE} -ac 1 -y {{}}" +) def listen_to_audio(config: FrigateConfig, event_queue: mp.Queue) -> None: @@ -36,55 +44,19 @@ def listen_to_audio(config: FrigateConfig, event_queue: mp.Queue) -> None: AudioEventMaintainer(camera, stop_event) -class AudioDetectProcess: - def __init__( - self, - name, - detection_queue, - out_events, - ): - self.name = name - self.out_events = out_events - self.detection_queue = detection_queue - self.detect_process = None - self.start_or_restart() - - def stop(self): - # if the process has already exited on its own, just return - if self.detect_process and self.detect_process.exitcode: - return - self.detect_process.terminate() - logging.info("Waiting for detection process to exit gracefully...") - self.detect_process.join(timeout=30) - if self.detect_process.exitcode is None: - logging.info("Detection process didnt exit. Force killing...") - self.detect_process.kill() - self.detect_process.join() - logging.info("Detection process has exited...") - - def start_or_restart(self): - self.detection_start.value = 0.0 - if (self.detect_process is not None) and self.detect_process.is_alive(): - self.stop() - self.detect_process = mp.Process( - target=run_detector, - name=f"detector:{self.name}", - args=( - self.name, - self.detection_queue, - self.out_events, - ), - ) - self.detect_process.daemon = True - self.detect_process.start() - - class AudioEventMaintainer(threading.Thread): def __init__(self, camera: CameraConfig, stop_event: mp.Event) -> None: threading.Thread.__init__(self) self.name = f"{camera.name}_audio_event_processor" self.config = camera self.stop_event = stop_event + self.shape = (int(round(AUDIO_DURATION * AUDIO_SAMPLE_RATE)),) + + def detect_audio(self) -> None: + pass + + def listen_to_audio(self) -> None: + pass def run(self) -> None: self.pipe = f"{CACHE_DIR}/{self.config.name}-audio"