From 98b15597bcd2d64ac24a335bff641305c041e412 Mon Sep 17 00:00:00 2001 From: CroneKorkN Date: Sun, 1 Jun 2025 11:10:12 +0200 Subject: [PATCH] wip --- create_chunks.py | 39 ------------------------------- process_chunks.py => process | 12 ++++++---- process_chunks_.py => process_old | 0 record | 33 ++++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 44 deletions(-) delete mode 100755 create_chunks.py rename process_chunks.py => process (78%) rename process_chunks_.py => process_old (100%) create mode 100755 record diff --git a/create_chunks.py b/create_chunks.py deleted file mode 100755 index df9201b..0000000 --- a/create_chunks.py +++ /dev/null @@ -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() \ No newline at end of file diff --git a/process_chunks.py b/process similarity index 78% rename from process_chunks.py rename to process index 1106c6b..5e468e9 100755 --- a/process_chunks.py +++ b/process @@ -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) diff --git a/process_chunks_.py b/process_old similarity index 100% rename from process_chunks_.py rename to process_old diff --git a/record b/record new file mode 100755 index 0000000..7cad6a1 --- /dev/null +++ b/record @@ -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