sonosketch/batch_generate.py
2026-04-13 16:52:32 -05:00

59 lines
2.1 KiB
Python

"""Batch generation script — 100 outputs across instruments and parameter permutations."""
import subprocess
import sys
import itertools
import random
import os
BASE = os.path.dirname(os.path.abspath(__file__))
PYTHON = os.path.join(BASE, "ace-step", ".venv", "Scripts", "python.exe")
SCRIPT = os.path.join(BASE, "hum2inst.py")
INPUT = os.path.join(BASE, "input", "bum bum bum [2026-04-10 230403].wav")
OUTPUT = os.path.join(BASE, "output", "batch-bumbum")
instruments = ["piano", "guitar", "saxophone", "violin", "flute",
"cello", "trumpet", "organ", "marimba", "harmonica"]
# Parameter combos: (strength, guidance)
param_combos = [
(0.2, 5.0),
(0.3, 5.0), # our best default
(0.4, 5.0),
(0.3, 7.0),
(0.3, 3.0),
]
# 10 instruments x 5 param combos x 2 takes = 100 outputs
takes_per_combo = 2
count = 0
total = len(instruments) * len(param_combos) * takes_per_combo
print(f"Generating {total} outputs...")
for instrument in instruments:
for strength, guidance in param_combos:
seeds = [random.randint(0, 2**31 - 1) for _ in range(takes_per_combo)]
for seed in seeds:
count += 1
print(f"\n[{count}/{total}] {instrument} str={strength} guide={guidance} seed={seed}")
cmd = [
PYTHON, SCRIPT, INPUT,
"--instrument", instrument,
"--output", OUTPUT,
"--strength", str(strength),
"--noise-strength", "0.0",
"--guidance", str(guidance),
"--seed", str(seed),
]
result = subprocess.run(cmd, capture_output=True, text=True)
# Print just the output/log lines
for line in result.stdout.splitlines():
if "Output saved" in line or "Run log" in line:
print(f" {line.strip()}")
if result.returncode != 0:
err_lines = [l for l in result.stderr.splitlines() if "ERROR" in l]
for l in err_lines:
print(f" FAILED: {l.strip()}")
print(f"\nDone! {count} outputs in {OUTPUT}/")