1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# lilchinese — live 高橋メソッド subtitles for spoken Chinese
Speak Chinese into your mic → huge black-on-white Chinese phrases fill the screen,
one short phrase at a time. 100% local: no Google, no cloud, no network at runtime.
```
parec (mic) ──► sherpa-onnx streaming zipformer (zh, int8) ──► SSE ──► Firefox kiosk
20 ms reads offline, on CPU, decode chunk 320 ms local Noto Sans CJK SC Black
```
## Why this shape
- **ASR in Go, pixels in the browser.** The Go side owns the audio path (a long-lived
stream that must not hiccup); the browser owns text layout, CJK font shaping, screen
fitting and fullscreen — things a Go GUI toolkit makes you fight for.
- **Server-sent events, not WebSocket.** The stream is one-way, so SSE via `net/http`
needs zero dependencies and reconnects by itself.
- **Firefox is fine.** Because recognition happens in the local binary, Firefox never
touches a speech service; it is only a renderer. (Firefox has no Web Speech API in
any case — which is exactly why the ASR lives here.)
## Setup
```sh
./scripts/fetch-model.sh # 133 MB, int8 streaming zipformer, Chinese
go build -o lilchinese . # needs gcc (cgo) + prebuilt sherpa-onnx libs
```
## Run
```sh
./lilchinese # mic → Firefox kiosk, fullscreen
./lilchinese -record talk.mp4 # same, but also record screen + mic
./lilchinese -wav speech.wav # play a file through the pipeline instead
./lilchinese -debug # overlay "N字 340ms" in the corner
```
Exit kiosk with `Alt+F4` (there is no chrome to click). `Ctrl+C` in the terminal stops
everything and finalizes a recording.
Then just talk. Silence holds the last phrase on screen — that is the Takahashi rhythm:
one short thought per screen, replaced on the next one.
## Flags
| flag | default | meaning |
|---|---|---|
| `-chars` | `9` | max characters per slide (the whole point: keep it short) |
| `-preview` | `3` | don't replace a full slide with a shorter in-progress phrase than this |
| `-source` | system default | PulseAudio source name (`pactl list short sources`) |
| `-model` | auto-detect `models/` | model directory |
| `-browser` | `firefox --kiosk {url}` | how to open the display; `{url}` substituted; empty = don't launch |
| `-record` | off | ffmpeg: `x11grab` + `pulse` → h264/aac mp4 |
| `-threads` | `2` | onnxruntime threads |
| `-addr` | `127.0.0.1:8787` | HTTP/SSE listen address |
| `-wav` | off | feed an audio file (paced realtime) instead of the mic |
## Latency, honestly
- Model lookahead: **320 ms** (`decode_chunk_len=32` frames in this model). Recognition
cannot show a syllable before its chunk is complete — that is the floor for any
streaming ASR.
- Plumbing (audio read → SSE → paint): **~35 ms** measured (`ts - cap` in the SSE payload).
- So: text appears roughly a third of a second behind your voice, then grows in 320 ms
steps. There is no zero-latency speech recognizer; this is about as close as it gets
while staying offline.
To trade accuracy for latency, point `-model` at a CTC streaming model instead
(`sherpa-onnx-streaming-zipformer-small-ctc-zh-int8-2025-04-01`, 21 MB) — non-autoregressive,
smaller chunks, noticeably faster to emit, somewhat less accurate.
## Look and feel
- Font stack starts at `Noto Sans CJK SC Black` (already installed here); size is
auto-fitted so the phrase fills 90% × 86% of the screen, whatever its length.
- Phrase changes slam in with a 90 ms scale/fade; refinements of the same phrase are
updated in place so the text doesn't flicker.
- Design preview without a mic or model: open `web/index.html?text=现在我开始` in any browser.
## Notes
- Slides break on `,。、;:?!…` and at `-chars`, whichever comes first.
- The binary links the shared libs from the Go module cache
(`rpath` → `.../pkg/mod/github.com/k2-fsa/sherpa-onnx-go-linux@v1.13.8/lib/...`).
If you wipe the module cache, rebuild.
- Screen blanking will ruin a long talk: `xset s off -dpms`.
- Recording captures the whole screen, so start it after the kiosk window is up
(it auto-delays 1.5 s).
## Layout
```
main.go mic → ASR → slide splitting → SSE, recorder, browser launch
web/index.html the whole UI (autofit, pop transition, EventSource client)
scripts/fetch-model.sh
models/ gitignored
```
|