Repository navigation
feat(interpretation): stream live AI speech and preserve listener recovery #1465
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from 1 commit
87e0bac
97f0bfc
680d005
8896cc1
10e6a4b
6044f0f
fd5eda9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -854,8 +854,8 @@ function finishSegmentWithDelay(seg, seqId) { | |
| var isTranslationActive = | ||
| Boolean(translationLangSelect.value) && mode !== "original"; | ||
|
|
||
| if (!isTranslationActive || seg.empty) { | ||
| // Nothing to read or hear (no translation wanted, or an empty one): advance immediately. | ||
| if (!isTranslationActive || seg.empty || (ttsSyncEnabled && seg.error)) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium · Playback failures still pause the queue When an audio buffer is ready but the browser throws while scheduling or starting its playback, the audio-playback catch calls Route terminal playback failures through the same immediate-advance path as synthesis errors. Prompt for AI agentsIn `portal/static/js/listener-event.js` at line 857:
**Playback failures still pause the queue**
When an audio buffer is ready but the browser throws while scheduling or starting its playback, the audio-playback catch calls `finishSegmentWithDelay` without setting `seg.error`, so this guard falls through to the timed reading delay and holds the next buffered segment.
Route terminal playback failures through the same immediate-advance path as synthesis errors. |
||
| // Failed AI speech must not hold up the next sentence; its text stays in history. | ||
| isSegmentPlaying = false; | ||
| delete segmentStore[seqId]; | ||
| expectedSeq++; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -743,6 +743,77 @@ async function run() { | |
| await waitFor(() => timeline.length >= 2); | ||
| assert(order() === '[31,32]', 'the feed plays its first two sentences in order, got ' + order()); | ||
| assert(gapless(), 'back to back'); | ||
|
|
||
| console.log('\n── AI voice continues after a failed segment (#415) ──'); | ||
|
|
||
| useFakeTimers(); | ||
| try { | ||
| for (const error of ['tts_error', 'tts_timeout', 'tts_unavailable', 'pipeline_failed', null]) { | ||
| timeline = []; | ||
| choose(translationLangSelect, 'fr'); | ||
| sendFloorSegment(1, 'failed-1', 'Failed sentence', 'Phrase indisponible.', 'text'); | ||
| for (const stage of ['text', 'audio']) sendFloorSegment(2, 'ready-2', 'Next sentence', 'Phrase suivante.', stage); | ||
| assert(order() === '[]', 'ready speech waits while the preceding segment is still pending'); | ||
|
|
||
| ttsSocket().onmessage({ | ||
| data: bundleFrame({ seq: 1, segment_id: 'failed-1', caption: 'Failed sentence', | ||
| translation: error === 'pipeline_failed' ? '' : 'Phrase indisponible.', error, audio_pending: false }), | ||
| }); | ||
| const outcome = error || 'no_audio'; | ||
| assert(order() === '[2]', outcome + ': ready speech is scheduled without a caption-reading pause, got ' + order()); | ||
| assert(historyBox.textContent.includes('Failed sentence'), outcome + ': the failed sentence keeps its caption'); | ||
| if (error !== 'pipeline_failed') { | ||
| assert(historyBox.textContent.includes('Phrase indisponible.'), outcome + ': translated text remains readable'); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium · Repeated captions hide later losses When a later error type loses its segment’s history after an earlier iteration rendered the same text, when a later error-specific path drops that segment’s caption or translation, the repeated strings and uncleared Use distinct caption and translation text for each error case, or assert against the history row for the current sequence. Prompt for AI agentsIn `tests/test_listener_event.js` at lines 764-766:
**Repeated captions hide later losses**
When a later error type loses its segment’s history after an earlier iteration rendered the same text, when a later error-specific path drops that segment’s caption or translation, the repeated strings and uncleared `historyBox` let the assertions at lines 764 and 766 pass because an earlier iteration already rendered the same text; the loop therefore does not verify history retention for each failure case.
Use distinct caption and translation text for each error case, or assert against the history row for the current sequence. |
||
| } | ||
| const beforeLateAudio = order(); | ||
| sendFloorSegment(1, 'failed-1', 'Failed sentence', 'Phrase indisponible.', 'audio'); | ||
| assert(order() === beforeLateAudio, outcome + ': late audio from the failed sentence is not replayed'); | ||
| } | ||
|
|
||
| timeline = []; | ||
| choose(translationLangSelect, 'fr'); | ||
| for (const seq of [1, 2]) { | ||
| ttsSocket().onmessage({ | ||
| data: bundleFrame({ seq, segment_id: 'unavailable-' + seq, caption: 'Unavailable ' + seq, | ||
| translation: 'Indisponible.', error: 'tts_unavailable', audio_pending: false }), | ||
| }); | ||
| } | ||
| sendFloorSegment(3, 'ready-3', 'Available', 'Disponible.', 'audio'); | ||
| assert(order() === '[3]', 'consecutive synthesis failures do not accumulate reading pauses'); | ||
|
|
||
| timeline = []; | ||
| choose(translationLangSelect, 'fr'); | ||
| sendFloorSegment(1, 'pending-1', 'Pending', 'En attente.', 'text'); | ||
| sendFloorSegment(2, 'ready-2', 'Ready', 'Prête.', 'audio'); | ||
| assert(order() === '[]', 'a segment still awaiting audio is not skipped'); | ||
| sendFloorSegment(1, 'pending-1', 'Pending', 'En attente.', 'audio'); | ||
| runTimers(30); | ||
| assert(order() === '[1,2]', 'pending audio that succeeds still plays in sentence order'); | ||
| assert(gapless(), 'successful recovery keeps the scheduled audio contiguous'); | ||
|
|
||
| // Caption-only listeners keep their reading time even when voice synthesis failed. | ||
| ttsToggle.checked = false; | ||
| ttsToggle.dispatchEvent(new Event('change')); | ||
| choose(translationLangSelect, 'fr'); | ||
| ttsSocket().onmessage({ | ||
| data: bundleFrame({ seq: 1, segment_id: 'reading-1', caption: 'Reading control first', | ||
| translation: 'Première phrase.', error: 'tts_error', audio_pending: false }), | ||
| }); | ||
| ttsSocket().onmessage({ | ||
| data: bundleFrame({ seq: 2, segment_id: 'reading-2', caption: 'Reading control second', | ||
| translation: 'Deuxième phrase.', error: null, audio_pending: false }), | ||
| }); | ||
| assert(!historyBox.textContent.includes('Reading control second'), 'text-only mode holds the next caption for reading'); | ||
| runTimers(2500); | ||
| assert(historyBox.textContent.includes('Reading control second'), 'text-only mode advances after the normal reading delay'); | ||
| } finally { | ||
| choose(translationLangSelect, 'fr'); | ||
| fakeTimers.clear(); | ||
| globalThis.setTimeout = realSetTimeout; | ||
| globalThis.clearTimeout = realClearTimeout; | ||
| ttsToggle.checked = true; | ||
| ttsToggle.dispatchEvent(new Event('change')); | ||
| } | ||
| window.AudioScheduler = stubScheduler; | ||
|
|
||
| console.log('\n── Empty translations (#1184) ──'); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Medium · Captions advance before listeners can read
When the voice toggle remains enabled after selecting a language without synchronized TTS, and an errored or text-only segment arrives,
finishSegmentWithDelaytreats the savedttsSyncEnabledflag and anyseg.erroras proof that speech failed, even when TTS is inactive or synthesis was not attempted. It skips the reading delay, so the next caption advances too soon.Base immediate advancement on an actual failed speech attempt for the selected language, rather than the saved toggle and generic
seg.errorflag.Prompt for AI agents