wip
This commit is contained in:
parent
98588ab2a0
commit
da4d78aa8f
1 changed files with 10 additions and 10 deletions
18
process
18
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"):
|
||||
try:
|
||||
process_recording(filename)
|
||||
except Exception as e:
|
||||
print(f"Error processing {filename}: {e}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Reference in a new issue