From 78455c67406808fc1da9f8655708738f10e30d23 Mon Sep 17 00:00:00 2001 From: wuhei Date: Thu, 19 Nov 2026 19:29:21 +0100 Subject: settle short sentences on screen when the speaker pauses MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- main.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 9d60178..c8fd0bc 100644 --- a/main.go +++ b/main.go @@ -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 -- cgit v1.2.3