fix: recordings keep only what was played, newest waiting request kept, video pages opened play
- Playback tells the worker how much of each request was played (tts_played); the worker keeps a spoken answer's recording only that far (an answer stopped mid-way no longer keeps its unheard rest, and is marked stopped); nothing played or never reported: no file. - Old recording day folders are also removed with the first recording of each new day. - response.interrupt off, latest: a request whose final comes after a newer one's is replaced instead of replacing it. - botBrowser presses play on a page's paused main player also after open, not only after a click. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -246,7 +246,8 @@ class Session:
|
||||
self.names: dict[str, str] = {}
|
||||
self.speakers: dict[str, _Speaker] = {}
|
||||
self.tts_requests: dict[str, TtsRequest] = {}
|
||||
# With recordings on: each spoken answer's text and mono samples until it is done.
|
||||
# With recordings on: each spoken answer's text and mono samples, kept until it is made and the
|
||||
# app said how much of it was played (`tts_played`).
|
||||
self.tts_recorded: dict[str, dict] = {}
|
||||
# Spoken replies whose speech was cancelled while the brain was still answering.
|
||||
self.cancelled_replies: set[str] = set()
|
||||
@@ -390,7 +391,7 @@ class Session:
|
||||
kind = msg.get("type")
|
||||
handler = {"speaking_end": self._on_speaking_end, "speaker_leave": self._on_speaker_leave,
|
||||
"config": self._on_config, "tts": self._on_tts, "tts_cancel": self._on_tts_cancel,
|
||||
"tts_speed": self._on_tts_speed,
|
||||
"tts_speed": self._on_tts_speed, "tts_played": self._on_tts_played,
|
||||
"voice_join": self._on_voice_join, "voice_leave": lambda m: self._leave_voice(),
|
||||
"member_join": self._on_member_join, "member_leave": self._on_member_leave,
|
||||
"chat_message": self._on_chat_message, "chat_edit": self._on_chat_edit,
|
||||
@@ -462,8 +463,11 @@ class Session:
|
||||
self.error("bad_message", "this tts id is already closed", id=rid)
|
||||
return
|
||||
if self.worker.recorder is not None:
|
||||
rec = self.tts_recorded.setdefault(rid, {"text": "", "pcm": [], "at": None})
|
||||
rec = self.tts_recorded.setdefault(rid, {"text": "", "pcm": [], "at": None, "rate": req.rate,
|
||||
"made": False, "played": None})
|
||||
rec["text"] += text
|
||||
while len(self.tts_recorded) > 50: # never reported as played: not kept forever
|
||||
self.tts_recorded.pop(next(iter(self.tts_recorded)))
|
||||
tts.feed(req, text, more)
|
||||
|
||||
def _on_tts_cancel(self, msg: dict) -> None:
|
||||
@@ -959,13 +963,34 @@ class Session:
|
||||
|
||||
def _tts_done(self, req: TtsRequest) -> None:
|
||||
self.tts_requests.pop(req.id, None)
|
||||
rec = self.tts_recorded.pop(req.id, None)
|
||||
if rec is not None and rec["pcm"] and self.worker.recorder is not None:
|
||||
self.worker.recorder.spoke(rec["at"], req.id, rec["text"], np.concatenate(rec["pcm"]), req.rate,
|
||||
req.cancelled or req.failed)
|
||||
rec = self.tts_recorded.get(req.id)
|
||||
if rec is not None:
|
||||
rec["made"] = True
|
||||
self._record_spoken(req.id)
|
||||
self.send({"type": "tts_done", "id": req.id, "chunks": req.chunks, "cancelled": req.cancelled,
|
||||
"failed": req.failed})
|
||||
self._delivered(req.id, not (req.cancelled or req.failed))
|
||||
|
||||
def _on_tts_played(self, msg: dict) -> None:
|
||||
"""How much of a spoken answer the app played: the recording keeps that much."""
|
||||
rec = self.tts_recorded.get(msg.get("id"))
|
||||
played = msg.get("played")
|
||||
if rec is None or isinstance(played, bool) or not isinstance(played, int) or played < 0:
|
||||
return
|
||||
rec["played"], rec["cancelled"] = played, bool(msg.get("cancelled"))
|
||||
self._record_spoken(msg["id"])
|
||||
|
||||
def _record_spoken(self, rid: str) -> None:
|
||||
"""Keep a spoken answer once it is made and the app said how much of it was heard (whole
|
||||
sentences, the last one maybe cut off by a stop)."""
|
||||
rec = self.tts_recorded.get(rid)
|
||||
if rec is None or not rec["made"] or rec["played"] is None:
|
||||
return
|
||||
self.tts_recorded.pop(rid)
|
||||
heard = rec["pcm"][:rec["played"]]
|
||||
if heard and self.worker.recorder is not None:
|
||||
self.worker.recorder.spoke(rec["at"], rid, rec["text"], np.concatenate(heard), rec["rate"],
|
||||
rec["cancelled"])
|
||||
|
||||
def _tts_error(self, req: TtsRequest, message: str) -> None:
|
||||
self.error("tts_failed", message, id=req.id)
|
||||
|
||||
Reference in New Issue
Block a user