feat: per-scene sfx via elevenlabs (milestone a of #25)#26
Merged
Conversation
The first audio-bed retention lever from the SFX/Music + Gemini plan (#25). Per-scene generated sound effects landing on the existing SFX lane that PR #20 placeholders wired. **Backend** (`packages/core`) - `elevenlabs/sfx.ts` — `generateSoundEffect(apiKey, prompt, opts)` mirrors the existing `synthesize()` shape: returns mp3 bytes + format. Clamps duration to 0.5..22, prompt influence to 0..1. Surfaces ElevenLabsError with the raw HTTP detail so the studio can show a meaningful 502. - `script/sfx/manifest.ts` — append-only manifest at `assets/sfx/sfx.manifest.json`. Three anchors (scene-start / accent-word / scene-end). Pure-helper `resolveSfxStart` does the anchor → absolute-time math; `resolveSfxStartForScene` wraps it with scene + cursor lookup so the assembler can call it directly. - `assemble.ts` reads the manifest once per assemble, groups by sceneId, and emits `<audio data-track-index="3" data-timeline-group="sfx">` elements alongside the existing voiceover audio. Already-existing SFX lane placeholder picks them up natively — no runtime/timeline changes. - 4 new storyline routes: POST /storyline/sfx-suggest Haiku 4.5 → 1-3 prompt+anchor ideas POST /storyline/sfx-generate ElevenLabs → mp3 + manifest append GET /storyline/sfx current manifest DELETE /storyline/sfx/:entryId manifest remove (audio file kept) All four cost-tracked (`script.storyline.sfx.suggest` / `.generate`). Suggest is ~$0.001/call; generate is one ElevenLabs SFX credit. **Frontend** (`packages/studio`) - New `🔊 Add SFX` per-card AI action. Click → Haiku returns 1-3 prompt ideas, rendered in a new amber-tinted suggestion stack below the regular Haiku stack. Each row shows label + prompt + duration + anchor + rationale + 🔊 Generate button. Clicking Generate calls the ElevenLabs route, writes the file, refreshes the manifest, and re-reads the script (so the SFX immediately lands on the timeline's SFX lane). - New emerald "SFX on lane" stack on each card lists already-applied SFX with HTML5 `<audio controls>` audition + Remove button. - `StorylineTab` adds three independent state maps (proposed / applied / generationStatus) so the UI stays responsive while ElevenLabs generates one and the user previews another. **Tests** (`packages/core`) - 10 anchor-math cases covering scene-start / scene-end (with SFX longer than the scene → clamps to sceneStart, never preceding it), accent-word interpolation (0, mid, last, past-last clamps to last, negative clamps to 0, empty narration falls back to scene-start), custom focal-line fractions. Tests: 729 core (+10) + 281 studio passing. Lint, format, typecheck clean. Verified live: 16 scene cards render, 16 "🔊 Add SFX" buttons visible, zero console errors. Plan: #25 (Milestone A of six). Next milestones (B Music, C Gemini render review, D Image analysis, E Scroll test, F Retention map) layer on this same SFX manifest pattern + applyPatch pipeline. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
First audio-bed retention lever from the SFX/Music + Gemini plan (#25). Per-scene generated sound effects landing on the existing SFX lane that PR #20's placeholders wired.
Summary
generateSoundEffect()ElevenLabs client · SFX manifest (append-only, three anchors) · 4 new storyline routes (suggest / generate / get / delete) · assembler emits<audio data-track-index="3">per manifest entryHow it composes
Architecture notes
assets/sfx/sfx.manifest.json. The assembler reads it at assemble time. Keepsscript.jsonpurely about narration + scene visual decisions.scene-start,accent-word,scene-end. Covers ~95% of cinematic usage. Resist adding offsets until users ask.DELETE /sfx/:entryIdremoves the manifest entry but leaves the audio file on disk so the user can recover by hand-editing JSON.script.storyline.sfx.suggest(Haiku); generate logsscript.storyline.sfx.generate(ElevenLabs). The CostBadge already aggregates by op.Test plan
assets/sfx/s04-sfx-….mp3, an emerald "SFX on lane" row appears with playable audio, and the master HTML's SFX lane shows the new clip on the timeline.Milestone A of #25 — what's next
Each subsequent milestone reuses the manifest pattern +
applyPatchpipeline that this PR puts in place.🤖 Generated with Claude Code