From 67646a689d26be92f4df100dc5d1b11c4dfb05c4 Mon Sep 17 00:00:00 2001 From: CroneKorkN Date: Sun, 1 Jun 2025 13:42:55 +0200 Subject: [PATCH] wip --- process | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/process b/process index 3eddca1..8961ee8 100755 --- a/process +++ b/process @@ -20,6 +20,7 @@ DETECT_FREQUENCY_TO = DETECT_FREQUENCY + DETECT_FREQUENCY_TOLERANCE # Hz ADJACENCY_FACTOR = 2 # area to look for noise around the target frequency AMPLITUDE_THRESHOLD = 200 # relative DB (rDB) (because not calibrated) BLOCK_SECONDS = 3 # seconds (longer means more frequency resolution, but less time resolution) +DETECTION_DISTANCE = 30 # seconds (minimum time between detections) def process_recording(filename): @@ -35,6 +36,10 @@ def process_recording(filename): samplerate = info.samplerate block_samples = int(BLOCK_SECONDS * samplerate) + # initialize to a very old date + last_detection_at = datetime.datetime.min.replace(tzinfo=recording_date.tzinfo) + is_detecting = False + # iterate blocks for num, block in enumerate(soundfile.blocks(path, blocksize=block_samples, overlap=int(block_samples*0.8))): block_date = recording_date + datetime.timedelta(seconds=num * BLOCK_SECONDS) @@ -58,12 +63,23 @@ def process_recording(filename): max_freq_detected = DETECT_FREQUENCY_FROM <= max_freq <= DETECT_FREQUENCY_TO amplitude_detected = max_amplitude > AMPLITUDE_THRESHOLD low_noise_detected = noise < 0.1 + no_recent_detection = is_detecting or (block_date - last_detection_at).total_seconds() > DETECTION_DISTANCE # conclude detection - if max_freq_detected and amplitude_detected and low_noise_detected: + if ( + max_freq_detected and + amplitude_detected and + low_noise_detected and + no_recent_detection + ): + if not is_detecting: + is_detecting = True + last_detection_at = block_date + print("🔊") + print(f'{block_date}: {max_amplitude:.1f}rDB @ {max_freq:.1f}Hz ({noise:.3f}rDB noise)') - - + else: + is_detecting = False