askrobots / dbbasic-face
Public
Puppet Stage: a browser puppet that lip-syncs to local text-to-speech and takes stage directions, live or from a screenplay.
index.html · 17.7 KB · 404 lines
| 1 | <!DOCTYPE html> |
| 2 | <html lang="en"> |
| 3 | <head> |
| 4 | <meta charset="utf-8"> |
| 5 | <title>Puppet Stage</title> |
| 6 | <meta name="viewport" content="width=device-width, initial-scale=1"> |
| 7 | <style> |
| 8 | * { box-sizing: border-box; margin: 0; } |
| 9 | body { |
| 10 | font-family: -apple-system, "Segoe UI", sans-serif; |
| 11 | background: #14161d; color: #e6e8ee; |
| 12 | display: grid; grid-template-columns: 1fr 340px; |
| 13 | height: 100vh; overflow: hidden; |
| 14 | } |
| 15 | /* ---- clean mode: chromeless performance view (?clean) — hide the |
| 16 | authoring panel and teleprompter so #stage fills the whole window; the |
| 17 | show is driven from another tab/api, this is purely a display view. */ |
| 18 | body.clean { grid-template-columns: 1fr; } |
| 19 | body.clean aside { display: none; } |
| 20 | body.clean #prompter { display: none; } |
| 21 | |
| 22 | main { display: flex; flex-direction: column; min-width: 0; } |
| 23 | |
| 24 | #stage { |
| 25 | position: relative; flex: 1; overflow: hidden; |
| 26 | background: #1a1e2e; |
| 27 | } |
| 28 | |
| 29 | /* ---- frames: independent rectangular sub-stages, positioned by % rect */ |
| 30 | #frames { position: absolute; inset: 0; } |
| 31 | .frame { position: absolute; overflow: hidden; } |
| 32 | .frame-bg { |
| 33 | position: absolute; inset: 0; |
| 34 | background: linear-gradient(#2b3350 0%, #3d4670 62%, #23283c 62%, #1a1e2e 100%); |
| 35 | } |
| 36 | .frame-content { |
| 37 | position: absolute; inset: 0; |
| 38 | display: flex; align-items: center; justify-content: center; |
| 39 | pointer-events: none; |
| 40 | } |
| 41 | .content-text { |
| 42 | font-size: 28px; font-weight: 700; color: #fff; |
| 43 | text-shadow: 0 2px 6px rgba(0,0,0,.6); padding: 12px 20px; |
| 44 | } |
| 45 | .frame-camera { |
| 46 | position: absolute; inset: 0; |
| 47 | transform-origin: 0 0; |
| 48 | transition: transform .9s cubic-bezier(.22,.61,.36,1); |
| 49 | } |
| 50 | .frame-pos { |
| 51 | position: absolute; bottom: 9%; left: 50%; |
| 52 | transform: translateX(-50%); |
| 53 | } |
| 54 | .frame-flip { transform-origin: 50% 100%; } |
| 55 | .frame-flip svg { display: block; filter: drop-shadow(0 14px 10px rgba(0,0,0,.35)); } |
| 56 | |
| 57 | /* ---- actors: placed props/characters in addition to the primary ---- */ |
| 58 | .frame-actor { position: absolute; inset: 0; pointer-events: none; } |
| 59 | .prop-actor { |
| 60 | position: absolute; bottom: 9%; left: 50%; transform: translateX(-50%); |
| 61 | pointer-events: none; |
| 62 | } |
| 63 | .prop-actor svg, .prop-actor img { |
| 64 | height: 100%; width: auto; display: block; |
| 65 | filter: drop-shadow(0 10px 8px rgba(0,0,0,.3)); |
| 66 | } |
| 67 | |
| 68 | /* ---- overlays: above all frames, spans the whole broadcast */ |
| 69 | #overlays { position: absolute; inset: 0; pointer-events: none; z-index: 5; } |
| 70 | .overlay { |
| 71 | position: absolute; inset: 0; opacity: 0; |
| 72 | transition: opacity .4s ease; |
| 73 | } |
| 74 | .overlay.shown { opacity: 1; } |
| 75 | .overlay svg, .overlay img { width: 100%; height: 100%; display: block; } |
| 76 | |
| 77 | /* ---- captions: broadcast subtitle bar, above overlays */ |
| 78 | /* bottom nudged up from the original 8%: the lower-third overlay's bars |
| 79 | now occupy roughly the bottom 4%-23% of stage height (see |
| 80 | assets/overlays/lower-third.svg), which the old 8% caption position |
| 81 | sat squarely inside of. 25% clears that band so a long caption line |
| 82 | (which can stretch left past center at max-width) doesn't collide with |
| 83 | a lower-left lower-third billboard shown at the same time. */ |
| 84 | #captions { |
| 85 | position: absolute; left: 50%; bottom: 25%; transform: translateX(-50%); |
| 86 | max-width: 82%; padding: 8px 18px; border-radius: 10px; |
| 87 | background: rgba(10,12,18,.72); color: #fff; font-size: 20px; line-height: 1.4; |
| 88 | text-align: center; pointer-events: none; z-index: 6; |
| 89 | opacity: 0; transition: opacity .15s ease; |
| 90 | } |
| 91 | #captions.shown { opacity: 1; } |
| 92 | |
| 93 | /* ---- user-caption: delayed-CC style bar for the human's own words in |
| 94 | CONVERSATION MODE, top-center so it never collides with the character's |
| 95 | reply caption (which uses the bottom-anchored #captions bar above). */ |
| 96 | #user-caption { |
| 97 | position: absolute; left: 50%; top: 6%; transform: translateX(-50%); |
| 98 | max-width: 82%; padding: 6px 16px; border-radius: 10px; |
| 99 | background: rgba(10,12,18,.5); color: #c8cede; font-size: 16px; line-height: 1.4; |
| 100 | text-align: center; pointer-events: none; z-index: 6; |
| 101 | opacity: 0; transition: opacity .15s ease; |
| 102 | } |
| 103 | #user-caption.shown { opacity: 1; } |
| 104 | #user-caption .you-prefix { color: #7a81a0; font-weight: 700; margin-right: 4px; } |
| 105 | |
| 106 | /* ---- take: fullscreen transitions (iris/fade), above captions */ |
| 107 | #take { position: absolute; inset: 0; pointer-events: none; z-index: 7; display: none; } |
| 108 | #take .iris-hole { |
| 109 | position: absolute; top: 50%; left: 50%; width: 0; height: 0; |
| 110 | border-radius: 50%; background: transparent; |
| 111 | box-shadow: 0 0 0 9999px #000; transform: translate(-50%, -50%); |
| 112 | display: none; |
| 113 | } |
| 114 | |
| 115 | #prompter { |
| 116 | position: absolute; left: 12px; top: 12px; width: 300px; max-height: 45%; |
| 117 | overflow-y: auto; padding: 10px 12px; border-radius: 10px; |
| 118 | background: rgba(10,12,18,.78); font-size: 13px; line-height: 1.9; |
| 119 | display: none; backdrop-filter: blur(4px); z-index: 10; |
| 120 | } |
| 121 | #prompter.active { display: block; } |
| 122 | .p-line { opacity: .45; transition: opacity .2s; white-space: pre-wrap; } |
| 123 | .p-line.now { opacity: 1; color: #ffd479; font-weight: 600; } |
| 124 | |
| 125 | #toast { |
| 126 | position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%); |
| 127 | background: #b33; color: #fff; padding: 8px 16px; border-radius: 8px; |
| 128 | opacity: 0; transition: opacity .3s; pointer-events: none; font-size: 13px; |
| 129 | z-index: 10; |
| 130 | } |
| 131 | #toast.show { opacity: 1; } |
| 132 | |
| 133 | aside { |
| 134 | border-left: 1px solid #2a2e3d; padding: 16px; overflow-y: auto; |
| 135 | display: flex; flex-direction: column; gap: 18px; background: #191c26; |
| 136 | } |
| 137 | h1 { font-size: 15px; letter-spacing: .04em; } |
| 138 | h2 { font-size: 11px; text-transform: uppercase; letter-spacing: .1em; color: #8b93ab; } |
| 139 | section { display: flex; flex-direction: column; gap: 8px; } |
| 140 | input[type=text], select, textarea, button { |
| 141 | font: inherit; color: inherit; background: #232735; |
| 142 | border: 1px solid #343a4e; border-radius: 8px; padding: 8px 10px; |
| 143 | } |
| 144 | textarea { min-height: 170px; resize: vertical; font-family: ui-monospace, monospace; font-size: 12px; } |
| 145 | button { cursor: pointer; } |
| 146 | button:hover { background: #2e3448; } |
| 147 | .row { display: flex; gap: 8px; } |
| 148 | .row > * { flex: 1; min-width: 0; } |
| 149 | #actions { display: flex; flex-wrap: wrap; gap: 6px; } |
| 150 | #actions button { flex: 0 0 auto; font-size: 12px; padding: 6px 10px; } |
| 151 | .chips { display: flex; flex-wrap: wrap; gap: 6px; } |
| 152 | .chips button { flex: 0 0 auto; font-size: 12px; padding: 6px 10px; } |
| 153 | .chips button.on { background: #4c6ef5; border-color: #4c6ef5; } |
| 154 | .chips button.sel { background: #262c44; border-color: #4c6ef5; box-shadow: inset 0 0 0 1px rgba(76,110,245,.5); } |
| 155 | button.primary { background: #4c6ef5; border-color: #4c6ef5; } |
| 156 | button.primary:hover { background: #5c7cfa; } |
| 157 | input[type=range] { width: 100%; } |
| 158 | label { font-size: 12px; color: #8b93ab; } |
| 159 | #record-toggle.rec-on { background: #b33; border-color: #b33; } |
| 160 | #record-toggle.rec-on:hover { background: #c44; } |
| 161 | #ptt-btn { padding: 16px 10px; font-size: 15px; font-weight: 600; } |
| 162 | #ptt-btn.listening { background: #b33; border-color: #b33; } |
| 163 | #ptt-btn.listening:hover { background: #c44; } |
| 164 | #ptt-btn:disabled { opacity: .4; cursor: default; } |
| 165 | #ptt-btn:disabled:hover { background: #232735; } |
| 166 | #converse-status { font-size: 12px; color: #8b93ab; align-self: center; } |
| 167 | #converse-note { font-size: 12px; color: #8b93ab; } |
| 168 | #converse-hint { font-size: 11px; color: #565d78; } |
| 169 | #wait-btn:disabled { opacity: .4; cursor: default; } |
| 170 | #wait-btn:disabled:hover { background: #232735; } |
| 171 | #help-toggle { flex: 0 0 auto; font-weight: 700; } |
| 172 | |
| 173 | /* ---- help panel: grammar cheat sheet, over the stage ---- */ |
| 174 | #help-panel { |
| 175 | position: absolute; right: 12px; top: 12px; width: 340px; max-height: 80%; |
| 176 | overflow-y: auto; padding: 14px 16px; border-radius: 10px; |
| 177 | background: rgba(10,12,18,.88); font-size: 12px; line-height: 1.55; |
| 178 | display: none; backdrop-filter: blur(4px); z-index: 11; |
| 179 | } |
| 180 | #help-panel.active { display: block; } |
| 181 | #help-panel h3 { |
| 182 | font-size: 11px; text-transform: uppercase; letter-spacing: .08em; |
| 183 | color: #8b93ab; margin: 12px 0 4px; |
| 184 | } |
| 185 | #help-panel h3:first-child { margin-top: 0; } |
| 186 | #help-panel dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; margin: 0; } |
| 187 | #help-panel dt { font-family: ui-monospace, monospace; color: #ffd479; white-space: nowrap; } |
| 188 | #help-panel dd { margin: 0; color: #c8cede; } |
| 189 | #help-close { |
| 190 | position: absolute; right: 8px; top: 8px; width: 22px; height: 22px; |
| 191 | padding: 0; line-height: 1; font-size: 12px; border-radius: 6px; |
| 192 | } |
| 193 | </style> |
| 194 | </head> |
| 195 | <body> |
| 196 | <main> |
| 197 | <div id="stage"> |
| 198 | <div id="frames"></div> |
| 199 | <div id="overlays"></div> |
| 200 | <div id="captions"></div> |
| 201 | <div id="user-caption"></div> |
| 202 | <div id="take"><div class="iris-hole"></div></div> |
| 203 | <div id="prompter"></div> |
| 204 | <div id="toast"></div> |
| 205 | <div id="help-panel"> |
| 206 | <button type="button" id="help-close">✕</button> |
| 207 | |
| 208 | <h3>Speaking</h3> |
| 209 | <dl> |
| 210 | <dt>text</dt><dd>speak as the target frame's character</dd> |
| 211 | <dt>frame: text</dt><dd>speak on a named frame/actor id, or (once framed/placed) a character's own name, e.g. rex: text</dd> |
| 212 | <dt>(action) text</dt><dd>run an action while the line is spoken</dd> |
| 213 | </dl> |
| 214 | <p style="margin:6px 0 0;color:#8b93ab">Once a character is framed/placed you can target it by name anywhere an id works — <code>[rex sit]</code>, <code>rex: Hi!</code>, <code>[wear rex tophat]</code> — resolution order is frame id → actor id → name. A bracketed speaker line like <code>[left: Hi!]</code> is tolerated too, but prefer the unbracketed form.</p> |
| 215 | |
| 216 | <h3>Movement & camera</h3> |
| 217 | <dl> |
| 218 | <dt>[wait N]</dt><dd>pause N seconds</dd> |
| 219 | <dt>[walk to N]</dt><dd>glide to N% of stage width, or left|center|middle|right (25/50/75)</dd> |
| 220 | <dt>[enter from left|right]</dt><dd>walk on from offstage</dd> |
| 221 | <dt>[exit left|right]</dt><dd>walk off that side</dd> |
| 222 | <dt>[look left|right|up|down|front]</dt><dd>gaze direction</dd> |
| 223 | <dt>[view face|body]</dt><dd>camera close-up / full frame</dd> |
| 224 | <dt>[emote name]</dt><dd>alias for a held-pose action</dd> |
| 225 | <dt>[wave] [jump] …</dt><dd>any action name from the manifest</dd> |
| 226 | </dl> |
| 227 | |
| 228 | <h3>Scene & frames</h3> |
| 229 | <dl> |
| 230 | <dt>[layout preset]</dt><dd>single|split|stack|thirds|pip-tr|tl|br|bl</dd> |
| 231 | <dt>[frame id key:val …]</dt><dd>slot|bg|character|view|facing|rect:x,y,w,h</dd> |
| 232 | <dt>[frame id clear]</dt><dd>remove a frame (never the last one)</dd> |
| 233 | <dt>[scene bg]</dt><dd>set active frame's background</dd> |
| 234 | <dt>[frameId direction]</dt><dd>target that frame, e.g. [left wave]</dd> |
| 235 | <dt>?clean URL param</dt><dd>chromeless view: hides this panel & the prompter, stage fills the window — for vertical/Shorts recording</dd> |
| 236 | </dl> |
| 237 | |
| 238 | <h3>Content & overlays</h3> |
| 239 | <dl> |
| 240 | <dt>[show image:id]</dt><dd>content tile; fit:contain|cover</dd> |
| 241 | <dt>[lower-third "a" "b" hold:ms]</dt><dd>title bar (default hold 6000, hold:0 = persist)</dd> |
| 242 | <dt>[lower-third clear]</dt><dd>dismiss it early</dd> |
| 243 | <dt>[captions on|off]</dt><dd>subtitle bar for spoken lines</dd> |
| 244 | <dt>[iris|fade in|out ms]</dt><dd>fullscreen take (default 700ms)</dd> |
| 245 | </dl> |
| 246 | |
| 247 | <h3>Audio</h3> |
| 248 | <dl> |
| 249 | <dt>[music id]</dt><dd>crossfade to a looping track</dd> |
| 250 | <dt>[music off]</dt><dd>fade out music</dd> |
| 251 | <dt>[sfx id]</dt><dd>one-shot sound effect</dd> |
| 252 | </dl> |
| 253 | |
| 254 | <h3>Cast & props</h3> |
| 255 | <dl> |
| 256 | <dt>[place what at x scale:s]</dt><dd>place a prop/character actor (x: number or left|center|middle|right; id: behind: optional)</dd> |
| 257 | <dt>[id move N / scale N]</dt><dd>glide / resize a prop actor</dd> |
| 258 | <dt>[id spin] [id bounce]</dt><dd>prop actor flourishes</dd> |
| 259 | <dt>[wear target prop]</dt><dd>pin a prop to an anchor (default head)</dd> |
| 260 | <dt>[unwear target]</dt><dd>remove the worn prop</dd> |
| 261 | <dt>[remove id]</dt><dd>destroy a placed actor</dd> |
| 262 | <dt>[clear]</dt><dd>wipe actors, worn props, content & overlays</dd> |
| 263 | </dl> |
| 264 | |
| 265 | <h3>Settings</h3> |
| 266 | <dl> |
| 267 | <dt>[engine say|espeak]</dt><dd>switch TTS engine</dd> |
| 268 | <dt>[voice name]</dt><dd>set voice for current engine</dd> |
| 269 | <dt>[rate n]</dt><dd>TTS speech rate</dd> |
| 270 | </dl> |
| 271 | </div> |
| 272 | </div> |
| 273 | </main> |
| 274 | |
| 275 | <aside> |
| 276 | <h1>🎭 Puppet Stage</h1> |
| 277 | |
| 278 | <section> |
| 279 | <h2>Character</h2> |
| 280 | <select id="character"></select> |
| 281 | </section> |
| 282 | |
| 283 | <section> |
| 284 | <h2>Speak</h2> |
| 285 | <form id="say-form"> |
| 286 | <div class="row" style="margin-bottom:8px"> |
| 287 | <select id="engine"> |
| 288 | <option value="say">say (macOS)</option> |
| 289 | <option value="espeak">espeak</option> |
| 290 | </select> |
| 291 | <select id="voice"><option value="">default voice</option></select> |
| 292 | </div> |
| 293 | <div class="row"> |
| 294 | <input type="text" id="say-text" placeholder="Type something to say…" autocomplete="off"> |
| 295 | <button class="primary" style="flex:0 0 auto">Say</button> |
| 296 | </div> |
| 297 | </form> |
| 298 | <div class="row" style="align-items:center"> |
| 299 | <span id="audio-state" style="font-size:12px;color:#8b93ab">audio: —</span> |
| 300 | <button id="beep" type="button" style="flex:0 0 auto;font-size:12px">🔊 test beep</button> |
| 301 | </div> |
| 302 | </section> |
| 303 | |
| 304 | <section id="converse-section" style="display:none"> |
| 305 | <h2>Converse</h2> |
| 306 | <div id="converse-note">no character loaded</div> |
| 307 | <button type="button" id="ptt-btn">🎙 Hold to talk</button> |
| 308 | <div id="converse-hint">or hold Space (outside text fields)</div> |
| 309 | <div class="row"> |
| 310 | <input type="text" id="converse-text" placeholder="…or type instead" autocomplete="off"> |
| 311 | <button type="button" id="converse-send" style="flex:0 0 auto">Send</button> |
| 312 | </div> |
| 313 | <div class="row"> |
| 314 | <button type="button" id="converse-reset" style="flex:0 0 auto">new conversation</button> |
| 315 | <span id="converse-status">idle</span> |
| 316 | </div> |
| 317 | </section> |
| 318 | |
| 319 | <section> |
| 320 | <h2>Direct</h2> |
| 321 | <div class="chips" id="frame-target" style="display:none"></div> |
| 322 | <div id="actions"></div> |
| 323 | </section> |
| 324 | |
| 325 | <section> |
| 326 | <h2>Scene</h2> |
| 327 | <div class="chips" id="layout-buttons"> |
| 328 | <button type="button" data-preset="single">single</button> |
| 329 | <button type="button" data-preset="split">split</button> |
| 330 | <button type="button" data-preset="stack">stack</button> |
| 331 | <button type="button" data-preset="thirds">thirds</button> |
| 332 | <button type="button" data-preset="pip-tr">pip</button> |
| 333 | </div> |
| 334 | <select id="scene-bg"><option value="">background…</option></select> |
| 335 | <div class="chips"> |
| 336 | <button type="button" id="captions-toggle">CC off</button> |
| 337 | <button type="button" data-transition-name="fade" data-transition-dir="in">fade in</button> |
| 338 | <button type="button" data-transition-name="fade" data-transition-dir="out">fade out</button> |
| 339 | <button type="button" data-transition-name="iris" data-transition-dir="in">iris in</button> |
| 340 | <button type="button" data-transition-name="iris" data-transition-dir="out">iris out</button> |
| 341 | </div> |
| 342 | </section> |
| 343 | |
| 344 | <section id="cast-section" style="display:none"> |
| 345 | <h2>Cast & Props</h2> |
| 346 | <div class="row"> |
| 347 | <select id="place-what"></select> |
| 348 | <input type="number" id="place-x" min="1" max="99" value="50" style="width:64px;flex:0 0 64px"> |
| 349 | <button type="button" id="place-btn" style="flex:0 0 auto">Place</button> |
| 350 | </div> |
| 351 | <div class="row"> |
| 352 | <select id="wear-what"></select> |
| 353 | <button type="button" id="wear-btn" style="flex:0 0 auto">Wear</button> |
| 354 | <button type="button" id="unwear-btn" style="flex:0 0 auto">Unwear</button> |
| 355 | </div> |
| 356 | <div class="chips" id="actor-chips" style="display:none"></div> |
| 357 | </section> |
| 358 | |
| 359 | <section id="music-section" style="display:none"> |
| 360 | <h2>Music</h2> |
| 361 | <select id="music-select"><option value="">music…</option></select> |
| 362 | <button type="button" id="music-off">⏹ music off</button> |
| 363 | <div class="chips" id="sfx-buttons"></div> |
| 364 | </section> |
| 365 | |
| 366 | <section> |
| 367 | <label>walk to position</label> |
| 368 | <input type="range" id="walk" min="5" max="95" value="50"> |
| 369 | </section> |
| 370 | |
| 371 | <section> |
| 372 | <h2>Screenplay</h2> |
| 373 | <div class="row" id="example-row" style="flex-wrap:wrap"> |
| 374 | <select id="example"><option value="">example…</option></select> |
| 375 | <button type="button" id="load-example" style="flex:0 0 auto">Load</button> |
| 376 | <button type="button" id="record-toggle" style="flex:0 0 auto">● Record</button> |
| 377 | <button type="button" id="wait-btn" style="flex:0 0 auto" disabled>+wait 1s</button> |
| 378 | <button type="button" id="help-toggle" style="flex:0 0 auto">?</button> |
| 379 | </div> |
| 380 | <textarea id="script" spellcheck="false"></textarea> |
| 381 | <div class="row"> |
| 382 | <button class="primary" id="run-script">▶ Run</button> |
| 383 | <button id="stop-script">■ Stop</button> |
| 384 | </div> |
| 385 | </section> |
| 386 | </aside> |
| 387 | |
| 388 | <script> |
| 389 | // ?clean: chromeless performance view — hides the authoring panel (and |
| 390 | // teleprompter, via CSS) so #stage fills the whole window. Everything |
| 391 | // else (SSE, captions, overlays, transitions) keeps working; the show is |
| 392 | // driven from another tab or the API. Combinable with ?shot. |
| 393 | if (location.search.includes('clean')) document.body.classList.add('clean'); |
| 394 | |
| 395 | // ?shot: hold the load event open so headless screenshots capture the booted |
| 396 | // stage; ?shot&d=8000 extends the hold for later scene states (default 3s) |
| 397 | if (location.search.includes('shot')) { |
| 398 | const m = location.search.match(/d=(\d+)/); |
| 399 | document.write('<img src="/slowpx?d=' + (m ? m[1] : 3000) + '" style="display:none">'); |
| 400 | } |
| 401 | </script> |
| 402 | <script src="stage.js"></script> |
| 403 | </body> |
| 404 | </html> |