summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go20
1 files changed, 17 insertions, 3 deletions
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