From f86cd966b06cd22463d9e5ebd8a0b39643da884a Mon Sep 17 00:00:00 2001 From: CroneKorkN Date: Fri, 30 May 2025 22:00:57 +0200 Subject: [PATCH] wip --- process_chunks.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/process_chunks.py b/process_chunks.py index 0ae328e..0f4a5ab 100755 --- a/process_chunks.py +++ b/process_chunks.py @@ -4,7 +4,7 @@ import concurrent.futures import datetime import numpy as np import matplotlib.pyplot as plt -import soundfile as sf +import soundfile import scipy.signal from scipy.fft import fft, fftfreq import shutil @@ -29,7 +29,7 @@ def process_chunk(filename): print(f"🔍 Verarbeite {input_path}...") # Frequenzanalyse und Event-Erkennung - data, samplerate = sf.read(input_path) + data, samplerate = soundfile.read(input_path) if data.ndim > 1: data = data[:, 0] # nur Kanal 1 @@ -43,6 +43,7 @@ def process_chunk(filename): i = 0 last_event = -skip_samples + while i + chunk_samples <= len(data): clip = data[i:i+chunk_samples] @@ -53,7 +54,7 @@ def process_chunk(filename): return False base_energy = np.mean(Sxx[idx_base]) oct_energy = np.mean(Sxx[idx_oct]) - total_energy = np.mean(Sxx, axis=0).max() + total_energy = np.mean(Sxx[freqs <= 1000, :], axis=0).max() fft_vals = np.abs(fft(clip)) freqs = fftfreq(len(clip), 1/samplerate) @@ -73,7 +74,7 @@ def process_chunk(filename): flac_out = os.path.join(EVENT_DIR, f"{event_time}.flac") png_out = os.path.join(EVENT_DIR, f"{event_time}.png") - sf.write(flac_out, clip, samplerate, format='FLAC') + soundfile.write(flac_out, clip, samplerate, format='FLAC') plt.figure() plt.specgram(clip, Fs=samplerate, NFFT=NFFT, noverlap=NFFT//2, cmap='inferno', vmin=-90, vmax=-20) @@ -84,7 +85,7 @@ def process_chunk(filename): plt.savefig(png_out) plt.close() - print(f"Event: {event_time} peak_freq: {peak_freq:.9f} Hz, base_energy: {base_energy:.9f}, oct_energy: {oct_energy:.9f}, total_energy: {total_energy:.9f}") + print(f"Event: {event_time} peak_freq: {peak_freq:.9f} Hz, base_energy: {base_energy/total_energy:.9f}, oct_energy: {oct_energy/total_energy:.9f}, total_energy: {total_energy:.9f}") last_event = i i += skip_samples else: