summaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
Diffstat (limited to 'README.md')
-rw-r--r--README.md54
1 files changed, 52 insertions, 2 deletions
diff --git a/README.md b/README.md
index 39b16ff..694bdab 100644
--- a/README.md
+++ b/README.md
@@ -6,6 +6,8 @@ one short phrase at a time. 100% local: no Google, no cloud, no network at runti
```
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
+ │
+ └─► (optional) llama-server + Hy-MT2-1.8B ──► English line
```
## Why this shape
@@ -24,6 +26,9 @@ parec (mic) ──► sherpa-onnx streaming zipformer (zh, int8) ──► S
```sh
./scripts/fetch-model.sh # 133 MB, int8 streaming zipformer, Chinese
go build -o lilchinese . # needs gcc (cgo) + prebuilt sherpa-onnx libs
+
+./scripts/fetch-mt-model.sh # optional: 1.1 GB Hy-MT2-1.8B for English subtitles
+ # (needs llama-server from llama.cpp on PATH)
```
## Run
@@ -41,6 +46,42 @@ 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.
+## English subtitles (optional)
+
+Pass a local translation model and every phrase gets an English line underneath,
+translated on your own machine:
+
+```sh
+./lilchinese -translate-model models/mt/Hy-MT2-1.8B-Q4_K_M.gguf
+./lilchinese -translate-model models/mt/Hy-MT2-1.8B-Q4_K_M.gguf -record talk.mp4
+```
+
+`-translate-model` spawns `llama-server` itself (free port, waits for `/health`,
+killed on exit, log in `~/.cache/lilchinese/llama-server.log`). If you already run an
+OpenAI-compatible endpoint — llama-server, ollama, LM Studio — point at it instead and
+skip the spawn:
+
+```sh
+./lilchinese -translate http://127.0.0.1:11434 # ollama also speaks /v1/chat/completions
+./lilchinese -translate http://127.0.0.1:8080 -prompt '将以下文本翻译成英语:{text}'
+```
+
+How it behaves, and why:
+
+- **Hy-MT2-1.8B** is a dedicated zh→en translation model, which matters here: slides are
+ 9-character fragments, and general chat models (Qwen, GPT-class) hallucinate context
+ around fragments while claiming to translate. On this CPU it does **29–32 tok/s**, so a
+ phrase lands in **0.5–0.8 s**.
+- The English line is **sticky**: it is not tied to the 9 characters currently on screen.
+ A slide lives ~0.3 s while speaking continuously — no LLM can keep up with that, so the
+ translation lags the speaker by roughly one model call and updates as the sentence
+ grows, like an interpreter. It never blanks between phrases.
+- `-translate-window` (default 28) is how many characters of speech go to the model.
+ Larger = smoother/more context but slower; smaller = snappier, choppier fragments.
+- Translations are cached per phrase, so repeated words cost nothing.
+- Without `-translate`/`-translate-model` the page is laid out exactly as before — the
+ English line is only reserved when `?en=1` is passed to the page.
+
## Flags
| flag | default | meaning |
@@ -54,6 +95,11 @@ one short thought per screen, replaced on the next one.
| `-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 |
+| `-translate-model` | off | spawn llama-server with this `.gguf` for English subtitles |
+| `-translate` | off | use an already running OpenAI-compatible endpoint |
+| `-translate-window` | `28` | characters of speech sent to the translator |
+| `-prompt` | Hy-MT template | translation prompt, `{text}` substituted |
+| `-llama-server` / `-llama-args` / `-llama-threads` | `llama-server` / — / half the cores | spawned backend tuning |
## Latency, honestly
@@ -64,6 +110,8 @@ one short thought per screen, replaced on the next one.
- 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.
+- English is a second, slower lane: +0.5–0.8 s per phrase with Hy-MT2-1.8B on CPU
+ (`prompt_ms` ~300 ms warm, 30 tok/s decode). It rides along with each slide update.
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,
@@ -75,7 +123,8 @@ smaller chunks, noticeably faster to emit, somewhat less accurate.
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.
+- Design preview without a mic or model: open `web/index.html?text=现在我开始` in any
+ browser, and `web/index.html?en=1&text=现在我开始&t=Now I begin` to preview both lines.
## Notes
@@ -91,7 +140,8 @@ smaller chunks, noticeably faster to emit, somewhat less accurate.
```
main.go mic → ASR → slide splitting → SSE, recorder, browser launch
+translate.go optional local MT: llama-server supervision, debounce, sticky EN line
web/index.html the whole UI (autofit, pop transition, EventSource client)
-scripts/fetch-model.sh
+scripts/ fetch-model.sh (ASR), fetch-mt-model.sh (translation)
models/ gitignored
```