This commit is contained in:
CroneKorkN 2025-06-01 14:17:55 +02:00
parent 6d7acd11ee
commit ebe942f014
Signed by: cronekorkn
SSH key fingerprint: SHA256:v0410ZKfuO1QHdgKBsdQNF64xmTxOF8osF1LIqwTcVw

14
process
View file

@ -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) AMPLITUDE_THRESHOLD = 200 # relative DB (rDB) (because not calibrated)
BLOCK_SECONDS = 3 # seconds (longer means more frequency resolution, but less time resolution) BLOCK_SECONDS = 3 # seconds (longer means more frequency resolution, but less time resolution)
DETECTION_DISTANCE = 30 # seconds (minimum time between detections) 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): def process_recording(filename):
@ -35,7 +35,7 @@ def process_recording(filename):
path = os.path.join(RECORDINGS_DIR, filename) path = os.path.join(RECORDINGS_DIR, filename)
sound, samplerate = soundfile.read(path) sound, samplerate = soundfile.read(path)
samples_per_block = int(BLOCK_SECONDS * samplerate) 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 # get median amplitude for normalization
complex_amplitudes_global = rfft(sound) complex_amplitudes_global = rfft(sound)
@ -47,12 +47,12 @@ def process_recording(filename):
is_detecting = False is_detecting = False
# read blocks of audio data with overlap from sound variable # read blocks of audio data with overlap from sound variable
for num in range(0, len(sound) // (samples_per_block - overlap)): for block_num in range(0, len(sound) // (samples_per_block - overlapping_samples)):
start = num * (samples_per_block - overlap) start_sample = block_num * (samples_per_block - overlapping_samples)
end = start + samples_per_block end_sample = start_sample + samples_per_block
block = sound[start:end] 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) labels = rfftfreq(len(block), d=1/samplerate)
complex_amplitudes = rfft(block) complex_amplitudes = rfft(block)
absolute_amplitudes = np.abs(complex_amplitudes) absolute_amplitudes = np.abs(complex_amplitudes)