demo · v138
Streaming captions
The live-captioning use case. Source phrases arrive one at a time (as a real captioner would emit them). The translator emits a streaming response per chunk so the translated overlay updates immediately — no “wait for the whole paragraph” delay.
On-device model. First-time use triggers a model download. The demo falls back to a tiny phrasebook if the API or pair is unavailable.
checking Translator availability…
source — live captions arrive here
0 chunks · 0 ms latency
translated — streamed via translator.translateStreaming()
0 chunks · 0 ms latency
the streaming call
const t = await Translator.create({ sourceLanguage: "en", targetLanguage: "fr" });
// Streaming: get a ReadableStream of partial translations
const stream = await t.translateStreaming(longSentence);
const reader = stream.getReader();
let partial = "";
while (true) {
const { value, done } = await reader.read();
if (done) break;
partial = value.startsWith(partial)
? value // native accumulated chunk
: partial + value; // incremental stream chunk
caption.textContent = partial;
}
The demo normalizes both stream shapes: browser chunks that contain the full text so far and fallback chunks that contain only the latest token.