MVP: CLI wired to LiveKit driver + procedural avatar
Browse files- scripts/freestream.py +17 -25
scripts/freestream.py
CHANGED
|
@@ -26,19 +26,20 @@ sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
|
| 26 |
|
| 27 |
from freestream.events import EventLog
|
| 28 |
from freestream.presence import (
|
|
|
|
| 29 |
CapabilityShortfall,
|
| 30 |
DriverError,
|
| 31 |
ValidationError,
|
| 32 |
get_driver,
|
| 33 |
infer_platform,
|
| 34 |
list_drivers,
|
|
|
|
| 35 |
)
|
| 36 |
from freestream.persona import FidelityRung, VoiceBackend, select_rung
|
| 37 |
|
| 38 |
SKILL_DIR = Path(__file__).resolve().parent.parent
|
| 39 |
DEFAULT_IMAGE = SKILL_DIR / "assets" / "placeholder-avatar.jpg"
|
| 40 |
DEFAULT_VOICE = "piper-en_US-amy-medium"
|
| 41 |
-
SESSIONS_DIR = SKILL_DIR / ".freestream" / "sessions"
|
| 42 |
|
| 43 |
EX_OK, EX_CONFIG, EX_VALIDATION, EX_TRANSPORT, EX_SESSION, EX_TIMEOUT, EX_CAPABILITY = 0, 1, 2, 3, 4, 5, 6
|
| 44 |
|
|
@@ -106,7 +107,8 @@ def cmd_join(args) -> int:
|
|
| 106 |
rung = select_rung(prefer_gpu=not args.cpu_only)
|
| 107 |
eprint(f"Fidelity rung: {rung.name} | voice: {backend.name}")
|
| 108 |
|
| 109 |
-
|
|
|
|
| 110 |
session_root.mkdir(parents=True, exist_ok=True)
|
| 111 |
log = EventLog(session_root / "events.jsonl")
|
| 112 |
log.append("session.requested", platform=platform, driver=driver_name, bot_name=args.bot_name,
|
|
@@ -122,6 +124,8 @@ def cmd_join(args) -> int:
|
|
| 122 |
voice=voice,
|
| 123 |
system_prompt=system_prompt,
|
| 124 |
meeting_password=args.meeting_password,
|
|
|
|
|
|
|
| 125 |
)
|
| 126 |
except ValidationError as e:
|
| 127 |
eprint(f"Error: {e}")
|
|
@@ -140,8 +144,7 @@ def cmd_join(args) -> int:
|
|
| 140 |
return EX_CONFIG
|
| 141 |
|
| 142 |
# Rename the session directory to the real id so replay paths are stable.
|
| 143 |
-
|
| 144 |
-
|
| 145 |
# Pika-compatible first output: emitted immediately so the agent can capture it.
|
| 146 |
emit({"session_id": sid, "platform": platform, "status": "created"})
|
| 147 |
log.append("session.created", session_id=sid, driver=driver_name)
|
|
@@ -157,7 +160,7 @@ def cmd_join(args) -> int:
|
|
| 157 |
"bot": drv.bot_connected(sid)})
|
| 158 |
last_status = status
|
| 159 |
log.append("session.status", status=status)
|
| 160 |
-
if status == "ready":
|
| 161 |
log.append("session.ready", session_id=sid)
|
| 162 |
return EX_OK
|
| 163 |
if status in ("error", "closed"):
|
|
@@ -173,12 +176,8 @@ def cmd_join(args) -> int:
|
|
| 173 |
|
| 174 |
|
| 175 |
def cmd_leave(args) -> int:
|
| 176 |
-
drv = get_driver(args.driver or "browser")
|
| 177 |
try:
|
| 178 |
-
|
| 179 |
-
except CapabilityShortfall as e:
|
| 180 |
-
emit({"status": "capability_shortfall", "capability": e.capability, "remediation": e.remediation})
|
| 181 |
-
return EX_CAPABILITY
|
| 182 |
except DriverError as e:
|
| 183 |
eprint(f"Error: transport: {e}")
|
| 184 |
return EX_TRANSPORT
|
|
@@ -196,24 +195,17 @@ def cmd_generate_avatar(args) -> int:
|
|
| 196 |
"avatar. Clean background, warm expression, centered face, suitable "
|
| 197 |
"for video calls.")
|
| 198 |
|
| 199 |
-
# Local-first: bundled
|
| 200 |
-
|
| 201 |
try:
|
| 202 |
-
import freestream.
|
| 203 |
-
local_gen = avatar_gen.available()
|
| 204 |
except ImportError:
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
if local_gen:
|
| 208 |
-
path = local_gen.generate(prompt, out)
|
| 209 |
-
emit({"path": str(path), "size_bytes": Path(path).stat().st_size})
|
| 210 |
-
return EX_OK
|
| 211 |
|
| 212 |
-
if
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
emit({"path": str(out), "size_bytes": out.stat().st_size, "generated": False})
|
| 217 |
return EX_OK
|
| 218 |
|
| 219 |
emit({"status": "capability_shortfall", "capability": "image_generation",
|
|
|
|
| 26 |
|
| 27 |
from freestream.events import EventLog
|
| 28 |
from freestream.presence import (
|
| 29 |
+
SESSIONS_DIR,
|
| 30 |
CapabilityShortfall,
|
| 31 |
DriverError,
|
| 32 |
ValidationError,
|
| 33 |
get_driver,
|
| 34 |
infer_platform,
|
| 35 |
list_drivers,
|
| 36 |
+
shutdown_session,
|
| 37 |
)
|
| 38 |
from freestream.persona import FidelityRung, VoiceBackend, select_rung
|
| 39 |
|
| 40 |
SKILL_DIR = Path(__file__).resolve().parent.parent
|
| 41 |
DEFAULT_IMAGE = SKILL_DIR / "assets" / "placeholder-avatar.jpg"
|
| 42 |
DEFAULT_VOICE = "piper-en_US-amy-medium"
|
|
|
|
| 43 |
|
| 44 |
EX_OK, EX_CONFIG, EX_VALIDATION, EX_TRANSPORT, EX_SESSION, EX_TIMEOUT, EX_CAPABILITY = 0, 1, 2, 3, 4, 5, 6
|
| 45 |
|
|
|
|
| 107 |
rung = select_rung(prefer_gpu=not args.cpu_only)
|
| 108 |
eprint(f"Fidelity rung: {rung.name} | voice: {backend.name}")
|
| 109 |
|
| 110 |
+
session_id = __import__("uuid").uuid4().hex[:12]
|
| 111 |
+
session_root = SESSIONS_DIR / session_id
|
| 112 |
session_root.mkdir(parents=True, exist_ok=True)
|
| 113 |
log = EventLog(session_root / "events.jsonl")
|
| 114 |
log.append("session.requested", platform=platform, driver=driver_name, bot_name=args.bot_name,
|
|
|
|
| 124 |
voice=voice,
|
| 125 |
system_prompt=system_prompt,
|
| 126 |
meeting_password=args.meeting_password,
|
| 127 |
+
session_id=session_id,
|
| 128 |
+
session_dir=session_root,
|
| 129 |
)
|
| 130 |
except ValidationError as e:
|
| 131 |
eprint(f"Error: {e}")
|
|
|
|
| 144 |
return EX_CONFIG
|
| 145 |
|
| 146 |
# Rename the session directory to the real id so replay paths are stable.
|
| 147 |
+
sid = session_id
|
|
|
|
| 148 |
# Pika-compatible first output: emitted immediately so the agent can capture it.
|
| 149 |
emit({"session_id": sid, "platform": platform, "status": "created"})
|
| 150 |
log.append("session.created", session_id=sid, driver=driver_name)
|
|
|
|
| 160 |
"bot": drv.bot_connected(sid)})
|
| 161 |
last_status = status
|
| 162 |
log.append("session.status", status=status)
|
| 163 |
+
if status == "ready" or status in ("speaking", "thinking", "listening"):
|
| 164 |
log.append("session.ready", session_id=sid)
|
| 165 |
return EX_OK
|
| 166 |
if status in ("error", "closed"):
|
|
|
|
| 176 |
|
| 177 |
|
| 178 |
def cmd_leave(args) -> int:
|
|
|
|
| 179 |
try:
|
| 180 |
+
detail = shutdown_session(args.session_id)
|
|
|
|
|
|
|
|
|
|
| 181 |
except DriverError as e:
|
| 182 |
eprint(f"Error: transport: {e}")
|
| 183 |
return EX_TRANSPORT
|
|
|
|
| 195 |
"avatar. Clean background, warm expression, centered face, suitable "
|
| 196 |
"for video calls.")
|
| 197 |
|
| 198 |
+
# Local-first: bundled procedural avatar (freestream.avatar) — no model,
|
| 199 |
+
# no network, always available. A heavy local generator can plug in later.
|
| 200 |
try:
|
| 201 |
+
import freestream.avatar as avatar_mod
|
|
|
|
| 202 |
except ImportError:
|
| 203 |
+
avatar_mod = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 204 |
|
| 205 |
+
if avatar_mod is not None:
|
| 206 |
+
path = avatar_mod.generate_placeholder(out)
|
| 207 |
+
emit({"path": str(path), "size_bytes": Path(path).stat().st_size,
|
| 208 |
+
"generated": True, "generator": "procedural-face"})
|
|
|
|
| 209 |
return EX_OK
|
| 210 |
|
| 211 |
emit({"status": "capability_shortfall", "capability": "image_generation",
|