read-aloud: stream a long text over the voice gateways

A skill that resolves a long text (a book) can hand it to the scheduler's
speech channel and return immediately; the gateway that owns the chat drains it
and streams it with text-to-speech until the user stops it.

- semif_agent/speech.py: SpeechService + ReadAloud. A bounded queue a front end
  drains, plus a per-source streaming predicate (set_stream_check/supports) so a
  skill asks before it posts one. Neutral and stdlib-only.
- semif_agent/reading.py: the bookmarks.json beside the saved books (load/save/
  read a key -> last offset, atomic write) and a deterministic speakable
  chunker at paragraph/sentence boundaries.
- Scheduler owns the channel (scheduler.speech); SkillRunner passes it into
  every run's ActionContext, so a body reaches it as ctx.speech.
- gateway/service: registers stream_ready as the channel's capability
  predicate, and surface() routes a drained read to the platform that owns the
  run (a non-streaming adapter is traced and skipped, never handed a message it
  would drop).
- gateway/voice: streams the saved text through the daemon's Piper voice chunk
  by chunk, writing the bookmark before each chunk; a barge-in "stop" or any new
  command ends it.
- gateway/lxmf: a read goes to a chat that last messaged by voice as a sequence
  of Sideband HQ voice messages (Piper -> Opus/OGG, backpressure so a stop is
  prompt), with the same bookmark-per-chunk resume; a "stop" message or any new
  command interrupts it.
- A run that registers a read is terminal (read_aloud_terminal): the read is the
  answer, so assess:outcome must not re-dispatch the request (which otherwise
  authored a spurious skill).
- config.example.json regenerated with the new voice/lxmf read blocks.
This commit is contained in:
gabby committed 2026-10-17 23:29:53 +00:00
1 parent faebe8a53a
commit 894a85ec2d
18 files changed
+1478 -53

No files matched your search

+13
View File
@@ -41,6 +41,7 @@ from .provider import ProviderError
from .packs import disabled_categories, load_packs, merge_packs
from .queue import RequestQueue
from .skill import SkillRunner
from .speech import SpeechService
from .timers import TimerService
from .skills import (
CANNED_CATEGORIES,
@@ -436,6 +437,10 @@ class Scheduler:
for category in disabled_categories(config, self.packs):
self.tree.pop(category, None)
self.timers = TimerService(trace=self.trace, timezone=config.get("timezone"))
# Long-form read-aloud requests a skill posts for the voice front end.
# A body registers one and returns immediately; the gateway drains it
# and streams it with text-to-speech (see `semif_agent.speech`).
self.speech = SpeechService(trace=self.trace)
# Read-only introspection of the live tree for introspection skills
# (listing categories / the skills in one), supplied as a locked
# snapshot so a body never reaches into the scheduler.
@@ -444,6 +449,7 @@ class Scheduler:
engine=self.engine,
config=config,
timers=self.timers,
speech=self.speech,
admin=self,
catalog=self.catalog,
)
@@ -1064,6 +1070,13 @@ class Scheduler:
result=outcome.action_log or outcome.new_state or None,
)
verdict = outcome.outcome or ("done" if outcome.success else "failed")
if verdict == "continue" and self.speech.pending_for(request.id):
# The run handed off to a long-form read-aloud: the read IS the
# answer, so there is no further work for `assess:outcome` to find.
# Overriding to `done` keeps the chain from re-dispatching the
# request (which otherwise authors a spurious skill).
self.trace.append("read_aloud_terminal", request.id, skill=skill.name)
verdict = "done"
self.trace.append(
"assessed",
request.id,