From da4d78aa8f5a866d17a96e52fde87952b44eb697 Mon Sep 17 00:00:00 2001 From: CroneKorkN Date: Sun, 1 Jun 2025 18:41:15 +0200 Subject: [PATCH] wip --- process | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/process b/process index db8b4bf..ea335aa 100755 --- a/process +++ b/process @@ -44,27 +44,22 @@ def process_recording(filename): for block in soundfile.blocks(path, blocksize=samples_per_block, overlap=overlapping_samples): sample_num += samples_per_block - overlapping_samples - # get block date and calculate FFT - block_date = recording_date + datetime.timedelta(seconds=sample_num / samplerate) + # calculate FFT labels = rfftfreq(len(block), d=1/samplerate) complex_amplitudes = rfft(block) amplitudes = np.abs(complex_amplitudes) - # get amplitudes only between 100 and 1000 Hz + # get the frequency with the highest amplitude within the search range search_amplitudes = amplitudes[(labels >= DETECT_FREQUENCY_FROM/ADJACENCY_FACTOR) & (labels <= DETECT_FREQUENCY_TO*ADJACENCY_FACTOR)] search_labels = labels[(labels >= DETECT_FREQUENCY_FROM/ADJACENCY_FACTOR) & (labels <= DETECT_FREQUENCY_TO*ADJACENCY_FACTOR)] - - # get the frequency with the highest amplitude max_amplitude = max(search_amplitudes) max_amplitude_index = np.argmax(search_amplitudes) max_freq = search_labels[max_amplitude_index] + max_freq_detected = DETECT_FREQUENCY_FROM <= max_freq <= DETECT_FREQUENCY_TO - # get the average amplitude of the search frequencies + # calculate signal quality adjacent_amplitudes = amplitudes[(labels < DETECT_FREQUENCY_FROM) | (labels > DETECT_FREQUENCY_TO)] signal_quality = max_amplitude/np.mean(adjacent_amplitudes) - - # check for detection criteria - max_freq_detected = DETECT_FREQUENCY_FROM <= max_freq <= DETECT_FREQUENCY_TO good_signal_quality = signal_quality > MIN_SIGNAL_QUALITY # conclude detection @@ -72,6 +67,8 @@ def process_recording(filename): max_freq_detected and good_signal_quality ): + block_date = recording_date + datetime.timedelta(seconds=sample_num / samplerate) + # detecting an event if not current_event: current_event = { @@ -117,7 +114,10 @@ def main(): for filename in sorted(os.listdir(RECORDINGS_DIR)): if filename.endswith(".flac"): - process_recording(filename) + try: + process_recording(filename) + except Exception as e: + print(f"Error processing {filename}: {e}") if __name__ == "__main__":