mirror of
				https://github.com/blakeblackshear/frigate.git
				synced 2025-10-27 10:52:11 +01:00 
			
		
		
		
	Only run audio detection when audio is above noise threshold (#7078)
* Only run audio detection when audio is above noise threshold * Formatting * Fix event parsing * Update frigate/events/audio.py Co-authored-by: Blake Blackshear <blakeb@blakeshome.com> --------- Co-authored-by: Blake Blackshear <blakeb@blakeshome.com>
This commit is contained in:
		
							parent
							
								
									88fc0fac8f
								
							
						
					
					
						commit
						f37f034b6a
					
				@ -145,6 +145,12 @@ audio:
 | 
				
			|||||||
  enabled: False
 | 
					  enabled: False
 | 
				
			||||||
  # Optional: Configure the amount of seconds without detected audio to end the event (default: shown below)
 | 
					  # Optional: Configure the amount of seconds without detected audio to end the event (default: shown below)
 | 
				
			||||||
  max_not_heard: 30
 | 
					  max_not_heard: 30
 | 
				
			||||||
 | 
					  # Optional: Configure the min rms volume required to run audio detection (default: shown below)
 | 
				
			||||||
 | 
					  # As a rule of thumb:
 | 
				
			||||||
 | 
					  #  - 200 - high sensitivity
 | 
				
			||||||
 | 
					  #  - 500 - medium sensitivity
 | 
				
			||||||
 | 
					  #  - 1000 - low sensitivity
 | 
				
			||||||
 | 
					  min_volume: 500
 | 
				
			||||||
  # Optional: Types of audio to listen for (default: shown below)
 | 
					  # Optional: Types of audio to listen for (default: shown below)
 | 
				
			||||||
  listen:
 | 
					  listen:
 | 
				
			||||||
    - bark
 | 
					    - bark
 | 
				
			||||||
 | 
				
			|||||||
@ -413,6 +413,9 @@ class AudioConfig(FrigateBaseModel):
 | 
				
			|||||||
    max_not_heard: int = Field(
 | 
					    max_not_heard: int = Field(
 | 
				
			||||||
        default=30, title="Seconds of not hearing the type of audio to end the event."
 | 
					        default=30, title="Seconds of not hearing the type of audio to end the event."
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					    min_volume: int = Field(
 | 
				
			||||||
 | 
					        default=500, title="Min volume required to run audio detection."
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
    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."
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
				
			|||||||
@ -169,14 +169,18 @@ class AudioEventMaintainer(threading.Thread):
 | 
				
			|||||||
        if not self.feature_metrics[self.config.name]["audio_enabled"].value:
 | 
					        if not self.feature_metrics[self.config.name]["audio_enabled"].value:
 | 
				
			||||||
            return
 | 
					            return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        waveform = (audio / AUDIO_MAX_BIT_RANGE).astype(np.float32)
 | 
					        rms = np.sqrt(np.mean(np.absolute(np.square(audio.astype(np.float32)))))
 | 
				
			||||||
        model_detections = self.detector.detect(waveform)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for label, score, _ in model_detections:
 | 
					        # only run audio detection when volume is above min_volume
 | 
				
			||||||
            if label not in self.config.audio.listen:
 | 
					        if rms >= self.config.audio.min_volume:
 | 
				
			||||||
                continue
 | 
					            waveform = (audio / AUDIO_MAX_BIT_RANGE).astype(np.float32)
 | 
				
			||||||
 | 
					            model_detections = self.detector.detect(waveform)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            self.handle_detection(label, score)
 | 
					            for label, score, _ in model_detections:
 | 
				
			||||||
 | 
					                if label not in self.config.audio.listen:
 | 
				
			||||||
 | 
					                    continue
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                self.handle_detection(label, score)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self.expire_detections()
 | 
					        self.expire_detections()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -192,7 +196,7 @@ class AudioEventMaintainer(threading.Thread):
 | 
				
			|||||||
            )
 | 
					            )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if resp.status_code == 200:
 | 
					            if resp.status_code == 200:
 | 
				
			||||||
                event_id = resp.json()[0]["event_id"]
 | 
					                event_id = resp.json()["event_id"]
 | 
				
			||||||
                self.detections[label] = {
 | 
					                self.detections[label] = {
 | 
				
			||||||
                    "id": event_id,
 | 
					                    "id": event_id,
 | 
				
			||||||
                    "label": label,
 | 
					                    "label": label,
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user