wip
This commit is contained in:
parent
0990821d6d
commit
4756013c17
1 changed files with 11 additions and 11 deletions
|
@ -22,17 +22,6 @@ OVERTONE_FREQ = TARGET_FREQ * 2
|
|||
NFFT = 32768
|
||||
SKIP_SECONDS = 10
|
||||
|
||||
def detect_event(chunk):
|
||||
freqs, times, Sxx = scipy.signal.spectrogram(chunk, samplerate, nperseg=NFFT)
|
||||
idx_base = np.where((freqs >= TARGET_FREQ - TOLERANCE) & (freqs <= TARGET_FREQ + TOLERANCE))[0]
|
||||
idx_oct = np.where((freqs >= OVERTONE_FREQ - OVERTONE_TOLERANCE) & (freqs <= OVERTONE_FREQ + OVERTONE_TOLERANCE))[0]
|
||||
if len(idx_base) == 0 or len(idx_oct) == 0:
|
||||
return False
|
||||
base_energy = np.mean(Sxx[idx_base])
|
||||
oct_energy = np.mean(Sxx[idx_oct])
|
||||
total_energy = np.mean(Sxx, axis=0).max()
|
||||
return base_energy > THRESHOLD_BASE * total_energy and oct_energy > THRESHOLD_OCT * total_energy
|
||||
|
||||
def process_chunk(filename):
|
||||
input_path = os.path.join(OUTDIR, filename)
|
||||
print(f"🔍 Verarbeite {input_path}...")
|
||||
|
@ -47,6 +36,17 @@ def process_chunk(filename):
|
|||
padding_before = int(CLIP_PADDING_BEFORE * samplerate)
|
||||
padding_after = int(CLIP_PADDING_AFTER * samplerate)
|
||||
|
||||
def detect_event(chunk):
|
||||
freqs, times, Sxx = scipy.signal.spectrogram(chunk, samplerate, nperseg=NFFT)
|
||||
idx_base = np.where((freqs >= TARGET_FREQ - TOLERANCE) & (freqs <= TARGET_FREQ + TOLERANCE))[0]
|
||||
idx_oct = np.where((freqs >= OVERTONE_FREQ - OVERTONE_TOLERANCE) & (freqs <= OVERTONE_FREQ + OVERTONE_TOLERANCE))[0]
|
||||
if len(idx_base) == 0 or len(idx_oct) == 0:
|
||||
return False
|
||||
base_energy = np.mean(Sxx[idx_base])
|
||||
oct_energy = np.mean(Sxx[idx_oct])
|
||||
total_energy = np.mean(Sxx, axis=0).max()
|
||||
return base_energy > THRESHOLD_BASE * total_energy and oct_energy > THRESHOLD_OCT * total_energy
|
||||
|
||||
i = 0
|
||||
last_event = -skip_samples
|
||||
while i + chunk_samples <= len(data):
|
||||
|
|
Loading…
Reference in a new issue