This commit is contained in:
CroneKorkN 2025-06-01 11:10:12 +02:00
parent 834d260c96
commit 98b15597bc
Signed by: cronekorkn
SSH key fingerprint: SHA256:v0410ZKfuO1QHdgKBsdQNF64xmTxOF8osF1LIqwTcVw
4 changed files with 40 additions and 44 deletions

View file

@ -1,39 +0,0 @@
#!/usr/bin/env python3
import os
import subprocess
import datetime
import pytz
OUTDIR = "chunks"
CHUNK_SECONDS = 10800 # 3 Stunden
os.makedirs(OUTDIR, exist_ok=True)
def record_section():
tz = pytz.timezone("Europe/Berlin")
now = datetime.datetime.now(tz)
timestamp = now.strftime("%Y%m%d-%H%M%S")
filename = os.path.join(OUTDIR, f"{timestamp}.flac")
print(f"🎙️ Starte Aufnahme: {filename}")
cmd = [
"ffmpeg",
"-f", "pulse",
"-i", "alsa_input.usb-HANMUS_USB_AUDIO_24BIT_2I2O_1612310-00.analog-stereo",
"-ac", "1",
"-ar", "96000",
"-sample_fmt", "s32", # gerät kann nur 24bit, aber flac kann nur 32bit container
"-t", str(CHUNK_SECONDS),
"-c:a", "flac",
"-compression_level", "12",
filename
]
subprocess.run(cmd)
print(f"✅ Aufnahme abgeschlossen: {filename}")
def main():
while True:
record_section()
if __name__ == "__main__":
main()

View file

@ -12,9 +12,9 @@ import shutil
RECORDINGS_DIR = "recordings"
PROCESSED_RECORDINGS_DIR = "recordings/processed"
DETECTIONS_DIR = "events"
DETECT_FREQUENCY_FROM = 210
DETECT_FREQUENCY_TO = 212
CLIP_SECONDS = 1
DETECT_FREQUENCY_FROM = 208
DETECT_FREQUENCY_TO = 214
CLIP_SECONDS = 3
THRESHOLD_BASE = 0.1
OCTAVE_FACTOR = 0.1
CLIP_PADDING_BEFORE = 1
@ -30,12 +30,14 @@ def process_chunk(filename):
print(info)
for block in soundfile.blocks(path, blocksize=blocksize, overlap=0):
for num, block in enumerate(soundfile.blocks(path, blocksize=blocksize, overlap=int(blocksize*0.8))):
strengths = fft(block)
labels = fftfreq(len(block), d=1/samplerate)
# get the frequency with the highest strength
max_freq = labels[np.argmax(np.abs(strengths))]
print(max_freq)
if DETECT_FREQUENCY_FROM <= max_freq <= DETECT_FREQUENCY_TO:
print(f'{num}: {max_freq:.1f}')
def main():
os.makedirs(RECORDINGS_DIR, exist_ok=True)

33
record Executable file
View file

@ -0,0 +1,33 @@
#!/bin/sh
mkdir -p recordings
while true
do
# get date in ISO 8601 format with nanoseconds
OS=$(uname)
if [ "$OS" = "Darwin" ]; then
DATE=$(gdate --iso-8601=ns)
elif [ "$OS" = "Linux" ]; then
DATE=$(date --iso-8601=ns)
else
echo "Unsupported OS: $OS"
exit 2
fi
# record audio using ffmpeg
ffmpeg \
-y \
-f pulse \
-i "alsa_input.usb-HANMUS_USB_AUDIO_24BIT_2I2O_1612310-00.analog-stereo" \
-ac 1 \
-ar 96000 \
-sample_fmt s32 \
-t "3600" \
-c:a flac \
-compression_level 12 \
"recordings/$DATE.flac"
done