diff options
| author | wuhei <wuhei@users.noreply.github.com> | 2026-11-19 19:29:21 +0100 |
|---|---|---|
| committer | wuhei <wuhei@users.noreply.github.com> | 2026-11-19 19:29:21 +0100 |
| commit | 78455c67406808fc1da9f8655708738f10e30d23 (patch) | |
| tree | 9576aa52b20c40037e39e0c504bf5e4755963806 /main.go | |
| parent | b457d19d9b2c634570300d0f73087e18b4ec4a4a (diff) | |
| download | lilchinese-78455c67406808fc1da9f8655708738f10e30d23.tar.gz | |
settle short sentences on screen when the speaker pauses
A long sentence flipped through fragments and stopped on the last one: '我觉得今年
我的中文会说得好一些。' ended up on screen as '会说得好一些'. The frame that stays
up is also the frame that gets recorded, translated and logged, so it has to be the
whole sentence.
- -settle (default 20): at an endpoint, if the finished sentence is that short, it is
published whole and replaces the trailing fragment. Fragments still flip while you
speak, so the Takahashi rhythm is unchanged; -settle 0 restores it exactly.
- the fragment is no longer published for a sentence that is about to settle (one
look, not two), so there is no flash of a frame that is immediately replaced.
- tests: settles whole, long sentences still fragment, -settle 0 keeps fragments
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 20 |
1 files changed, 17 insertions, 3 deletions
@@ -262,6 +262,7 @@ func cleanSlide(s string) string { type presenter struct { max int // max characters per slide preview int // don't replace a full slide with a shorter preview than this + settle int // on a pause, sentences up to this many characters land whole emitted int // runes of the current utterance already turned into slides b *broker @@ -326,8 +327,20 @@ func (p *presenter) update(u string, capTS int64, endpoint bool) { } // Live tail: grows character by character while you keep talking. A very short // tail would blank a full slide, so keep the previous phrase until it grows. - if tail := cleanSlide(string(r[p.emitted:])); tail != "" && - (endpoint || utf8.RuneCountInString(tail) >= p.preview) { + tail := cleanSlide(string(r[p.emitted:])) + + // End of a sentence: fragments were fine while speaking, but the frame that stays + // up (and gets recorded, and translated, and logged) should be the whole sentence. + whole := "" + if endpoint { + if c := cleanSlide(strings.TrimSpace(u)); c != "" && utf8.RuneCountInString(c) <= p.settle { + whole = c + } + } + switch { + case whole != "": + p.b.publish(whole, capTS) + case tail != "" && (endpoint || utf8.RuneCountInString(tail) >= p.preview): p.b.publish(tail, capTS) } if p.onUtterance != nil && u != p.lastU && strings.TrimSpace(u) != "" { @@ -570,6 +583,7 @@ func main() { threads = flag.Int("threads", 2, "onnxruntime threads") chars = flag.Int("chars", 9, "max characters per slide") preview = flag.Int("preview", 3, "min characters before the next phrase replaces the current slide") + settle = flag.Int("settle", 20, "on a pause, show sentences up to this many characters whole (0 = off)") debug = flag.Bool("debug", false, "show latency/char-count overlay") logFile = flag.String("log", "sessions/", "session log written by Enter (a file, or a directory for a timestamped file)") @@ -616,7 +630,7 @@ func main() { stream := sherpa.NewOnlineStream(rec) b := newBroker() - pres := &presenter{max: *chars, preview: *preview, b: b} + pres := &presenter{max: *chars, preview: *preview, settle: *settle, b: b} cutReq, keepReq := new(atomic.Bool), new(atomic.Bool) var trRef atomic.Value // *translator, may stay nil |
