import argparse import math import os import struct import sys import time import wave from datetime import datetime, timezone ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) if ROOT not in sys.path: sys.path.insert(0, ROOT) from app import ( INFERENCE_MODE_HYBRID, INFERENCE_MODE_MF_ONLY, INFERENCE_MODE_QWEN_ONLY, process_audio, ) def _slug(text): return text.lower().replace(" + ", "_plus_").replace(" ", "_") def _ensure_synthetic_sample(audio_path): if os.path.exists(audio_path): return if os.path.basename(audio_path) != "public_domain_tone.wav": return os.makedirs(os.path.dirname(audio_path), exist_ok=True) sample_rate = 22050 segment_sec = 2.0 progression = [ (261.63, 329.63, 392.00), (293.66, 369.99, 440.00), (349.23, 440.00, 523.25), (392.00, 493.88, 587.33), ] frames = [] for chord in progression: total = int(segment_sec * sample_rate) for i in range(total): t = i / sample_rate attack = min(1.0, i / (0.05 * sample_rate)) release = min(1.0, (total - i) / (0.05 * sample_rate)) envelope = attack * release mixed = 0.0 for freq in chord: mixed += math.sin(2.0 * math.pi * freq * t) mixed = (mixed / len(chord)) * 0.35 * envelope sample = int(max(-1.0, min(1.0, mixed)) * 32767) frames.append(struct.pack("