wip
This commit is contained in:
parent
6626c3696d
commit
f86cd966b0
1 changed files with 6 additions and 5 deletions
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue