From e3c615b671065e64c94beb75a2ad491ed0abdb9a Mon Sep 17 00:00:00 2001 From: kxkm Date: Sat, 21 Mar 2026 21:06:13 +0100 Subject: [PATCH] fix: ai-bridge ACE-Step fallback for /generate/music Co-Authored-By: Claude Opus 4.6 (1M context) --- ai-bridge.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ai-bridge.js b/ai-bridge.js index 1fc43394..27e8509c 100644 --- a/ai-bridge.js +++ b/ai-bridge.js @@ -76,6 +76,14 @@ const server = http.createServer(async (req, res) => { } if (url.pathname === "/generate/music" && req.method === "POST") { const {prompt="ambient",duration=30,style="experimental"} = JSON.parse(await readBody(req)); + // Try ACE-Step first (20s for 4min, MIT) → fallback to MusicGen + try { + const aceOk = await fetch(ACE_STEP_URL + '/health', {signal:AbortSignal.timeout(2000)}).then(r=>r.json()).catch(()=>null); + if (aceOk && aceOk.ok) { + const ar = await fetch(ACE_STEP_URL + '/generate', {method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({prompt:prompt+', '+style,duration,steps:8}),signal:AbortSignal.timeout(300000)}); + if (ar.ok) { const buf = Buffer.from(await ar.arrayBuffer()); res.writeHead(200,{'Content-Type':'audio/wav','Content-Length':buf.length}); res.end(buf); return; } + } + } catch {} // ACE-Step unavailable, fall through try { const r = await fetch(`${TTS_URL}/compose`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({prompt:`${prompt}, ${style}`,duration}),signal:AbortSignal.timeout(300000)}); if (!r.ok) throw new Error(`TTS ${r.status}`);