This commit is contained in:
CroneKorkN 2025-05-30 22:00:57 +02:00
parent 6626c3696d
commit f86cd966b0
Signed by: cronekorkn
SSH key fingerprint: SHA256:v0410ZKfuO1QHdgKBsdQNF64xmTxOF8osF1LIqwTcVw

View file

@ -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: