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:
@@ -402,6 +402,9 @@ def test_with_recordings_on_each_utterance_and_spoken_answer_is_kept_as_a_wav_wi
|
||||
await recv_until(ws, lambda m: isinstance(m, dict) and m.get("type") == "final")
|
||||
await ws.send(json.dumps({"type": "tts", "id": "r1", "text": "오늘은 맑아요. 기온은 17.5도예요."}))
|
||||
await recv_until(ws, lambda m: isinstance(m, dict) and m.get("type") == "tts_done")
|
||||
# The app played both sentences to the end.
|
||||
await ws.send(json.dumps({"type": "tts_played", "id": "r1", "played": 2, "cancelled": False}))
|
||||
await asyncio.sleep(0.2)
|
||||
|
||||
asyncio.run(with_worker(body, tts=FakeTts(), recorder=recorder))
|
||||
recorder.close()
|
||||
@@ -446,3 +449,49 @@ def test_recordings_older_than_the_keep_days_are_removed_at_start(tmp_path):
|
||||
(tmp_path / "notes").mkdir() # not a day folder: left alone
|
||||
Recorder(tmp_path, now=datetime(2026, 11, 16, 12).timestamp()).close()
|
||||
assert sorted(p.name for p in tmp_path.iterdir()) == sorted([d.isoformat() for d in keep] + ["notes"])
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_a_spoken_answer_is_kept_only_as_far_as_the_app_played_it(tmp_path):
|
||||
import wave
|
||||
from voice_worker.recordings import Recorder
|
||||
|
||||
recorder = Recorder(tmp_path)
|
||||
|
||||
async def body(url):
|
||||
async with connect(url) as ws:
|
||||
await hello(ws)
|
||||
# Made in full, then stopped while its first sentence played.
|
||||
await ws.send(json.dumps({"type": "tts", "id": "r1", "text": "오늘은 맑아요. 기온은 17.5도예요."}))
|
||||
await recv_until(ws, lambda m: isinstance(m, dict) and m.get("type") == "tts_done")
|
||||
await ws.send(json.dumps({"type": "tts_played", "id": "r1", "played": 1, "cancelled": True}))
|
||||
# Stopped before any of it was heard: nothing to keep.
|
||||
await ws.send(json.dumps({"type": "tts", "id": "r2", "text": "두 번째 답이에요."}))
|
||||
await recv_until(ws, lambda m: isinstance(m, dict) and m.get("type") == "tts_done")
|
||||
await ws.send(json.dumps({"type": "tts_played", "id": "r2", "played": 0, "cancelled": True}))
|
||||
# Never reported as played (an older app): not kept as if it had been heard.
|
||||
await ws.send(json.dumps({"type": "tts", "id": "r3", "text": "세 번째 답이에요."}))
|
||||
await recv_until(ws, lambda m: isinstance(m, dict) and m.get("type") == "tts_done")
|
||||
await asyncio.sleep(0.2)
|
||||
|
||||
asyncio.run(with_worker(body, tts=FakeTts(), recorder=recorder))
|
||||
recorder.close()
|
||||
day, lines = _index(tmp_path)
|
||||
assert [(l["id"], l["cancelled"]) for l in lines] == [("r1", True)]
|
||||
with wave.open(str(day / lines[0]["file"])) as w:
|
||||
assert w.getnframes() == len("오늘은 맑아요.") * 10, "only the sentence that was played"
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_old_recordings_are_also_removed_while_the_worker_keeps_running(tmp_path):
|
||||
from datetime import datetime, timedelta
|
||||
import numpy as np
|
||||
from voice_worker.recordings import KEEP_DAYS, Recorder
|
||||
|
||||
start = datetime(2026, 11, 16, 12)
|
||||
r = Recorder(tmp_path, now=start.timestamp())
|
||||
r.said(start.timestamp(), "1", "A", "vc", "첫날", np.zeros(1600))
|
||||
later = start + timedelta(days=KEEP_DAYS) # the first recording of a day past the keep days
|
||||
r.said(later.timestamp(), "1", "A", "vc", "나중", np.zeros(1600))
|
||||
r.close()
|
||||
assert sorted(p.name for p in tmp_path.iterdir()) == [later.date().isoformat()]
|
||||
|
||||
Reference in New Issue
Block a user