bootshorn_investigation/create_chunks.py
2025-05-30 19:02:26 +02:00

52 lines
No EOL
1.5 KiB
Python

#!/usr/bin/env python3
import os
import subprocess
import datetime
import pytz
OUTDIR = "chunks_unprocessed"
DURATION = 10800 # 3 Stunden
SOURCE = "pulse" # funktioniert mit PulseAudio
os.makedirs(OUTDIR, exist_ok=True)
def get_next_section_start(now):
hour = now.hour
next_boundary = (hour // 3 + 1) * 3
if next_boundary >= 24:
next_time = now.replace(day=now.day, hour=0, minute=0, second=0, microsecond=0) + datetime.timedelta(days=1)
else:
next_time = now.replace(hour=next_boundary, minute=0, second=0, microsecond=0)
return next_time
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}")
next_start = get_next_section_start(now)
duration_seconds = int((next_start - now).total_seconds())
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(duration_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()