From ebe942f01447c325d59220187988847919b23a46 Mon Sep 17 00:00:00 2001 From: CroneKorkN Date: Sun, 1 Jun 2025 14:17:55 +0200 Subject: [PATCH] wip --- process | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/process b/process index 9a1e5a9..3df49a8 100755 --- a/process +++ b/process @@ -21,7 +21,7 @@ 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) -BLOCK_OVERLAP = 0.8 # overlap between blocks (0.8 means 80% overlap) +BLOCK_OVERLAP_FACTOR = 0.8 # overlap between blocks (0.8 means 80% overlap) def process_recording(filename): @@ -35,7 +35,7 @@ def process_recording(filename): path = os.path.join(RECORDINGS_DIR, filename) sound, samplerate = soundfile.read(path) samples_per_block = int(BLOCK_SECONDS * samplerate) - overlap = int(samples_per_block * BLOCK_OVERLAP) + overlapping_samples = int(samples_per_block * BLOCK_OVERLAP_FACTOR) # get median amplitude for normalization complex_amplitudes_global = rfft(sound) @@ -47,12 +47,12 @@ def process_recording(filename): is_detecting = False # read blocks of audio data with overlap from sound variable - for num in range(0, len(sound) // (samples_per_block - overlap)): - start = num * (samples_per_block - overlap) - end = start + samples_per_block - block = sound[start:end] + for block_num in range(0, len(sound) // (samples_per_block - overlapping_samples)): + start_sample = block_num * (samples_per_block - overlapping_samples) + end_sample = start_sample + samples_per_block + block = sound[start_sample:end_sample] - block_date = recording_date + datetime.timedelta(seconds=num * BLOCK_SECONDS) + block_date = recording_date + datetime.timedelta(seconds=block_num * BLOCK_SECONDS) labels = rfftfreq(len(block), d=1/samplerate) complex_amplitudes = rfft(block) absolute_amplitudes = np.abs(complex_amplitudes)