Puppet Stage: a browser puppet that lip-syncs to local text-to-speech and takes stage directions, live or from a screenplay.

0 downloads

Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/dbbasic-face.git
HTTPS
https://gitstable.com/git/askrobots/dbbasic-face.git
SSH
ssh://git@gitstable.com:2222/askrobots/dbbasic-face.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

Dan Quellhorst Converse: characters know they have bodies 52ca998 4 months, 1 week ago History
build.py · 3.1 KB · 90 lines
1#!/usr/bin/env python3
2"""Generate the DBBASIC stage page object from the main app's sources.
3
4Assembles puppet-stage/objects/puppet/stage.py from:
5 ../../public/index.html (stage DOM + CSS, script tags stripped)
6 ../../public/stage.js (verbatim frontend runtime)
7 ./shim.js (DBBASIC transport adapter, loaded first)
8 ../../characters/*/ (embedded as window.PUPPET_CHARACTERS)
9 ../../assets/music/*.json, ../../assets/sfx/*.json
10 (embedded as window.PUPPET_AUDIO — small JSON
11 note patterns, same embed-not-serve treatment
12 as characters)
13
14Re-run after changing any of those so the package cannot drift from the app.
15"""
16
17import json
18import re
19from pathlib import Path
20
21HERE = Path(__file__).resolve().parent
22ROOT = HERE.parent.parent
23OUT = HERE / "puppet-stage" / "objects" / "puppet" / "stage.py"
24
25index_html = (ROOT / "public" / "index.html").read_text()
26stage_js = (ROOT / "public" / "stage.js").read_text()
27shim_js = (HERE / "shim.js").read_text()
28
29css = re.search(r"<style>(.*?)</style>", index_html, re.S).group(1)
30body = re.search(r"<body>(.*?)</body>", index_html, re.S).group(1)
31body = re.sub(r"<script[^>]*>.*?</script>", "", body, flags=re.S).strip()
32
33characters = {}
34for manifest_path in sorted((ROOT / "characters").glob("*/manifest.json")):
35 manifest = json.loads(manifest_path.read_text())
36 svg = (manifest_path.parent / manifest["svg"]).read_text()
37 characters[manifest_path.parent.name] = {"manifest": manifest, "svg": svg}
38
39examples = {}
40for script_path in sorted((ROOT / "examples").glob("*.txt")):
41 examples[script_path.stem] = script_path.read_text()
42
43audio = {"music": {}, "sfx": {}}
44for kind in audio:
45 for asset_path in sorted((ROOT / "assets" / kind).glob("*.json")):
46 audio[kind][asset_path.stem] = json.loads(asset_path.read_text())
47
48html = f"""<!doctype html>
49<html lang="en">
50<head>
51<meta charset="utf-8">
52<title>Puppet Stage</title>
53<meta name="viewport" content="width=device-width, initial-scale=1">
54<style>{css}</style>
55</head>
56<body>
57{body}
58<script>window.PUPPET_CHARACTERS = {json.dumps(characters)};</script>
59<script>window.PUPPET_EXAMPLES = {json.dumps(examples)};</script>
60<script>window.PUPPET_AUDIO = {json.dumps(audio)};</script>
61<script>
62{shim_js}
63</script>
64<script>
65{stage_js}
66</script>
67</body>
68</html>
69"""
70
71assert "'''" not in html, "generated page would break the stage.py literal"
72
73stage_py = f'''"""Puppet Stage page object. GENERATED by integrations/dbbasic/build.py — do not edit.
74
75Serves the complete stage (HTML, CSS, runtime, characters) as one page.
76Speech and direction go through the puppet_speak and puppet_cues objects.
77"""
78
79_HTML = r\'\'\'{html}\'\'\'
80
81
82def GET(request):
83 return {{"content_type": "text/html; charset=utf-8", "body": _HTML}}
84'''
85
86OUT.parent.mkdir(parents=True, exist_ok=True)
87OUT.write_text(stage_py)
88print(f"wrote {OUT} ({len(stage_py)//1024} KB, characters: {', '.join(characters)}, "
89 f"examples: {', '.join(examples)}, music: {', '.join(audio['music'])}, "
90 f"sfx: {', '.join(audio['sfx'])})")