cvpfus Codex commited on
Commit
a1018e3
·
1 Parent(s): 921d7f6

Add optional auto-advance reader mode

Browse files

Co-authored-by: Codex <codex@openai.com>

Files changed (6) hide show
  1. FIELD_NOTES.md +2 -0
  2. README.md +2 -0
  3. app.py +1 -0
  4. scripts/verify.py +5 -0
  5. static/app.js +31 -7
  6. static/index.html +4 -0
FIELD_NOTES.md CHANGED
@@ -51,6 +51,8 @@ Kokoro is still the intended model-backed TTS path. For local resilience, the fr
51
 
52
  Reader settings are manifest-backed: the app exposes known Kokoro voices and speed bounds through `/api/article-manifest`, then the custom frontend renders the controls and passes the selected voice to `/api/speak`.
53
 
 
 
54
  Every model-facing backend path reports `elapsed_ms`. The frontend surfaces the latest end-to-end reader latency and stores per-item timing in the transcript, giving the build report concrete evidence for the small-model responsiveness claim.
55
 
56
  The app exposes `/api/award-evidence` and renders that data in the session panel, so the live demo can point directly to the hackathon bonus targets it is designed to satisfy.
 
51
 
52
  Reader settings are manifest-backed: the app exposes known Kokoro voices and speed bounds through `/api/article-manifest`, then the custom frontend renders the controls and passes the selected voice to `/api/speak`.
53
 
54
+ Auto-advance is intentionally opt-in. This keeps the default reader mode user-controlled while still supporting a continuous-reading demo path.
55
+
56
  Every model-facing backend path reports `elapsed_ms`. The frontend surfaces the latest end-to-end reader latency and stores per-item timing in the transcript, giving the build report concrete evidence for the small-model responsiveness claim.
57
 
58
  The app exposes `/api/award-evidence` and renders that data in the session panel, so the live demo can point directly to the hackathon bonus targets it is designed to satisfy.
README.md CHANGED
@@ -92,6 +92,8 @@ Kokoro remains the planned tiny-model TTS path. During local demos, if the serve
92
 
93
  The reader bar exposes Kokoro voice selection and speaking speed controls. Defaults come from `/api/article-manifest` so the UI, docs, and backend stay aligned.
94
 
 
 
95
  Reader-brain, image-description, speech, and image-generation responses include `elapsed_ms`. The session panel and transcript show recent latency so the Field Notes can discuss responsiveness with concrete numbers.
96
 
97
  The session panel also renders a manifest-backed demo checklist for Tiny Titan, Llama Champion, Off-Brand, and Field Notes evidence.
 
92
 
93
  The reader bar exposes Kokoro voice selection and speaking speed controls. Defaults come from `/api/article-manifest` so the UI, docs, and backend stay aligned.
94
 
95
+ Auto-advance is available as an opt-in reader control. It stays off by default so users keep manual control unless they choose continuous reading.
96
+
97
  Reader-brain, image-description, speech, and image-generation responses include `elapsed_ms`. The session panel and transcript show recent latency so the Field Notes can discuss responsiveness with concrete numbers.
98
 
99
  The session panel also renders a manifest-backed demo checklist for Tiny Titan, Llama Champion, Off-Brand, and Field Notes evidence.
app.py CHANGED
@@ -79,6 +79,7 @@ ARTICLE_IMAGES: list[dict[str, str]] = [
79
  READER_SETTINGS: dict[str, Any] = {
80
  "default_voice": "af_heart",
81
  "default_speed": 1.0,
 
82
  "voices": [
83
  {"id": "af_heart", "label": "Heart"},
84
  {"id": "af_bella", "label": "Bella"},
 
79
  READER_SETTINGS: dict[str, Any] = {
80
  "default_voice": "af_heart",
81
  "default_speed": 1.0,
82
+ "default_auto_advance": False,
83
  "voices": [
84
  {"id": "af_heart", "label": "Heart"},
85
  {"id": "af_bella", "label": "Bella"},
scripts/verify.py CHANGED
@@ -89,6 +89,7 @@ def verify_routes() -> None:
89
  assert_true("latencyStatus" in home.text, "Home route should include latency status")
90
  assert_true("voiceControl" in home.text, "Home route should include voice control")
91
  assert_true("speedValue" in home.text, "Home route should include speed value output")
 
92
  assert_true("transcriptLog" in home.text, "Home route should include transcript log")
93
  assert_true("awardEvidenceList" in home.text, "Home route should include award evidence list")
94
 
@@ -121,6 +122,10 @@ def verify_routes() -> None:
121
  len(manifest_payload["reader_settings"]["voices"]) >= 4,
122
  "Manifest should expose multiple Kokoro voice choices",
123
  )
 
 
 
 
124
  assert_true(
125
  len(manifest_payload["award_evidence"]) == 4,
126
  "Manifest should expose four award evidence items",
 
89
  assert_true("latencyStatus" in home.text, "Home route should include latency status")
90
  assert_true("voiceControl" in home.text, "Home route should include voice control")
91
  assert_true("speedValue" in home.text, "Home route should include speed value output")
92
+ assert_true("autoAdvanceControl" in home.text, "Home route should include auto-advance control")
93
  assert_true("transcriptLog" in home.text, "Home route should include transcript log")
94
  assert_true("awardEvidenceList" in home.text, "Home route should include award evidence list")
95
 
 
122
  len(manifest_payload["reader_settings"]["voices"]) >= 4,
123
  "Manifest should expose multiple Kokoro voice choices",
124
  )
125
+ assert_true(
126
+ manifest_payload["reader_settings"]["default_auto_advance"] is False,
127
+ "Manifest should default auto-advance off",
128
+ )
129
  assert_true(
130
  len(manifest_payload["award_evidence"]) == 4,
131
  "Manifest should expose four award evidence items",
static/app.js CHANGED
@@ -13,6 +13,7 @@ const audio = document.querySelector("#speechAudio");
13
  const voiceControl = document.querySelector("#voiceControl");
14
  const speedControl = document.querySelector("#speedControl");
15
  const speedValue = document.querySelector("#speedValue");
 
16
  const transcriptLog = document.querySelector("#transcriptLog");
17
  const copyTranscriptButton = document.querySelector("#copyTranscriptButton");
18
  const clearTranscriptButton = document.querySelector("#clearTranscriptButton");
@@ -44,6 +45,8 @@ let requestSerial = 0;
44
  let transcriptEntries = [];
45
  let imageDescriptions = new Map();
46
  let lastSpokenText = "";
 
 
47
 
48
  function updateSpeedValue() {
49
  speedValue.textContent = `${Number(speedControl.value).toFixed(2)}x`;
@@ -120,6 +123,7 @@ async function loadManifest() {
120
  speedControl.value = settings.default_speed;
121
  updateSpeedValue();
122
  }
 
123
  } catch {
124
  modelStatus.textContent = "Manifest unavailable";
125
  }
@@ -220,11 +224,26 @@ function stopAudio() {
220
  audio.pause();
221
  audio.removeAttribute("src");
222
  window.speechSynthesis?.cancel();
 
 
223
  playing = false;
224
  controls.play.textContent = "Play";
225
  }
226
 
227
- function browserSpeak(text) {
 
 
 
 
 
 
 
 
 
 
 
 
 
228
  if (!("speechSynthesis" in window)) {
229
  return false;
230
  }
@@ -234,6 +253,7 @@ function browserSpeak(text) {
234
  utterance.onend = () => {
235
  playing = false;
236
  controls.play.textContent = "Play";
 
237
  };
238
  window.speechSynthesis.speak(utterance);
239
  playing = true;
@@ -241,8 +261,10 @@ function browserSpeak(text) {
241
  return true;
242
  }
243
 
244
- async function speakNarration(text, serial) {
245
  lastSpokenText = text;
 
 
246
  const speech = await postJson("/api/speak", {
247
  text,
248
  voice: voiceControl.value || "af_heart",
@@ -252,7 +274,7 @@ async function speakNarration(text, serial) {
252
  if (serial !== requestSerial) return;
253
 
254
  if (speech.runtime === "fallback") {
255
- const spoke = browserSpeak(text);
256
  voiceStatus.textContent = spoke ? "Browser fallback" : "Transcript only";
257
  if (!spoke) {
258
  liveNarration.textContent = `${text} Audio fallback is unavailable. Transcript is visible.`;
@@ -263,7 +285,7 @@ async function speakNarration(text, serial) {
263
  if (speech.audio_url) {
264
  audio.src = speech.audio_url;
265
  await audio.play().catch(() => {
266
- const spoke = browserSpeak(text);
267
  voiceStatus.textContent = spoke ? "Browser fallback" : "Audio ready";
268
  liveNarration.textContent = spoke ? text : `${text} Audio is ready. Press Play to hear it.`;
269
  });
@@ -322,7 +344,7 @@ async function narrate(index) {
322
  runtimeStatus.textContent = result.runtime;
323
  liveNarration.textContent = result.narration;
324
 
325
- const speech = await speakNarration(result.narration, serial);
326
  const elapsedMs = (result.elapsed_ms || 0) + (speech?.elapsed_ms || 0);
327
  latencyStatus.textContent = formatElapsed(elapsedMs);
328
  addTranscriptEntry({
@@ -359,7 +381,7 @@ async function summarizeCurrentSection() {
359
  runtimeStatus.textContent = result.runtime;
360
  liveNarration.textContent = result.narration;
361
 
362
- const speech = await speakNarration(result.narration, serial);
363
  const elapsedMs = (result.elapsed_ms || 0) + (speech?.elapsed_ms || 0);
364
  latencyStatus.textContent = formatElapsed(elapsedMs);
365
  addTranscriptEntry({
@@ -438,7 +460,8 @@ controls.play.addEventListener("click", () => {
438
  playing = true;
439
  controls.play.textContent = "Pause";
440
  } else if (lastSpokenText) {
441
- browserSpeak(lastSpokenText);
 
442
  } else {
443
  narrate(currentIndex);
444
  }
@@ -453,6 +476,7 @@ updateSpeedValue();
453
  audio.addEventListener("ended", () => {
454
  playing = false;
455
  controls.play.textContent = "Play";
 
456
  });
457
 
458
  document.addEventListener("keydown", (event) => {
 
13
  const voiceControl = document.querySelector("#voiceControl");
14
  const speedControl = document.querySelector("#speedControl");
15
  const speedValue = document.querySelector("#speedValue");
16
+ const autoAdvanceControl = document.querySelector("#autoAdvanceControl");
17
  const transcriptLog = document.querySelector("#transcriptLog");
18
  const copyTranscriptButton = document.querySelector("#copyTranscriptButton");
19
  const clearTranscriptButton = document.querySelector("#clearTranscriptButton");
 
45
  let transcriptEntries = [];
46
  let imageDescriptions = new Map();
47
  let lastSpokenText = "";
48
+ let activeAutoAdvance = false;
49
+ let activeSpeechSerial = 0;
50
 
51
  function updateSpeedValue() {
52
  speedValue.textContent = `${Number(speedControl.value).toFixed(2)}x`;
 
123
  speedControl.value = settings.default_speed;
124
  updateSpeedValue();
125
  }
126
+ autoAdvanceControl.checked = Boolean(settings?.default_auto_advance);
127
  } catch {
128
  modelStatus.textContent = "Manifest unavailable";
129
  }
 
224
  audio.pause();
225
  audio.removeAttribute("src");
226
  window.speechSynthesis?.cancel();
227
+ activeAutoAdvance = false;
228
+ activeSpeechSerial = 0;
229
  playing = false;
230
  controls.play.textContent = "Play";
231
  }
232
 
233
+ function maybeAutoAdvance(serial) {
234
+ if (!enabled || !autoAdvanceControl.checked || !activeAutoAdvance || serial !== requestSerial) {
235
+ return;
236
+ }
237
+ const nextIndex = currentIndex + 1;
238
+ if (nextIndex < nodes.length) {
239
+ window.setTimeout(() => narrate(nextIndex), 250);
240
+ } else {
241
+ liveNarration.textContent = "End of article.";
242
+ activeAutoAdvance = false;
243
+ }
244
+ }
245
+
246
+ function browserSpeak(text, serial) {
247
  if (!("speechSynthesis" in window)) {
248
  return false;
249
  }
 
253
  utterance.onend = () => {
254
  playing = false;
255
  controls.play.textContent = "Play";
256
+ maybeAutoAdvance(serial);
257
  };
258
  window.speechSynthesis.speak(utterance);
259
  playing = true;
 
261
  return true;
262
  }
263
 
264
+ async function speakNarration(text, serial, autoAdvance = false) {
265
  lastSpokenText = text;
266
+ activeAutoAdvance = autoAdvance;
267
+ activeSpeechSerial = serial;
268
  const speech = await postJson("/api/speak", {
269
  text,
270
  voice: voiceControl.value || "af_heart",
 
274
  if (serial !== requestSerial) return;
275
 
276
  if (speech.runtime === "fallback") {
277
+ const spoke = browserSpeak(text, serial);
278
  voiceStatus.textContent = spoke ? "Browser fallback" : "Transcript only";
279
  if (!spoke) {
280
  liveNarration.textContent = `${text} Audio fallback is unavailable. Transcript is visible.`;
 
285
  if (speech.audio_url) {
286
  audio.src = speech.audio_url;
287
  await audio.play().catch(() => {
288
+ const spoke = browserSpeak(text, serial);
289
  voiceStatus.textContent = spoke ? "Browser fallback" : "Audio ready";
290
  liveNarration.textContent = spoke ? text : `${text} Audio is ready. Press Play to hear it.`;
291
  });
 
344
  runtimeStatus.textContent = result.runtime;
345
  liveNarration.textContent = result.narration;
346
 
347
+ const speech = await speakNarration(result.narration, serial, true);
348
  const elapsedMs = (result.elapsed_ms || 0) + (speech?.elapsed_ms || 0);
349
  latencyStatus.textContent = formatElapsed(elapsedMs);
350
  addTranscriptEntry({
 
381
  runtimeStatus.textContent = result.runtime;
382
  liveNarration.textContent = result.narration;
383
 
384
+ const speech = await speakNarration(result.narration, serial, false);
385
  const elapsedMs = (result.elapsed_ms || 0) + (speech?.elapsed_ms || 0);
386
  latencyStatus.textContent = formatElapsed(elapsedMs);
387
  addTranscriptEntry({
 
460
  playing = true;
461
  controls.play.textContent = "Pause";
462
  } else if (lastSpokenText) {
463
+ activeAutoAdvance = false;
464
+ browserSpeak(lastSpokenText, requestSerial);
465
  } else {
466
  narrate(currentIndex);
467
  }
 
476
  audio.addEventListener("ended", () => {
477
  playing = false;
478
  controls.play.textContent = "Play";
479
+ maybeAutoAdvance(activeSpeechSerial);
480
  });
481
 
482
  document.addEventListener("keydown", (event) => {
static/index.html CHANGED
@@ -145,6 +145,10 @@
145
  <input id="speedControl" type="range" min="0.75" max="1.35" value="1" step="0.05" />
146
  <output id="speedValue" for="speedControl">1.00x</output>
147
  </label>
 
 
 
 
148
  <audio id="speechAudio"></audio>
149
  </section>
150
 
 
145
  <input id="speedControl" type="range" min="0.75" max="1.35" value="1" step="0.05" />
146
  <output id="speedValue" for="speedControl">1.00x</output>
147
  </label>
148
+ <label>
149
+ Auto
150
+ <input id="autoAdvanceControl" type="checkbox" />
151
+ </label>
152
  <audio id="speechAudio"></audio>
153
  </section>
154