summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrail Finder <wohilas@gmail.com>2025-05-17 13:33:00 +0300
committerGrail Finder <wohilas@gmail.com>2025-05-17 13:33:00 +0300
commitf7d1fbf73c2979220855522574ce3c01aa51e47a (patch)
tree695a1d12137884b455af87c194b27a81bd2997d5
parentd05d90474797977a5b1aad19a8c5277453dd754c (diff)
Fix: signal that llm is done
-rw-r--r--bot.go10
-rw-r--r--extra/audio.go27
2 files changed, 29 insertions, 8 deletions
diff --git a/bot.go b/bot.go
index 11dcbee..1475d1f 100644
--- a/bot.go
+++ b/bot.go
@@ -334,12 +334,6 @@ func chatRound(userMsg, role string, tv *tview.TextView, regen, resume bool) {
}
}
respText := strings.Builder{}
- // if tts is enabled
- // var audioStream *extra.AudioStream
- // if cfg.TTS_ENABLED {
- // audioStream = extra.RunOrator(orator)
- // // defer close(audioStream.DoneChan)
- // }
out:
for {
select {
@@ -354,6 +348,10 @@ out:
}
case <-streamDone:
botRespMode = false
+ if cfg.TTS_ENABLED {
+ // audioStream.TextChan <- chunk
+ extra.TTSFlushChan <- true
+ }
break out
}
}
diff --git a/extra/audio.go b/extra/audio.go
index ae3300c..531b08b 100644
--- a/extra/audio.go
+++ b/extra/audio.go
@@ -8,6 +8,7 @@ import (
"io"
"log/slog"
"net/http"
+ "strings"
"time"
"github.com/gopxl/beep"
@@ -17,8 +18,9 @@ import (
)
var (
- TTSTextChan = make(chan string, 1000)
- TTSDoneChan = make(chan bool, 1)
+ TTSTextChan = make(chan string, 1000)
+ TTSFlushChan = make(chan bool, 1)
+ TTSDoneChan = make(chan bool, 1)
)
type Orator interface {
@@ -39,6 +41,7 @@ type KokoroOrator struct {
func readroutine(orator Orator) {
tokenizer, _ := english.NewSentenceTokenizer(nil)
var sentenceBuf bytes.Buffer
+ var remainder strings.Builder
for {
select {
case chunk := <-TTSTextChan:
@@ -56,6 +59,26 @@ func readroutine(orator Orator) {
orator.GetLogger().Error("tts failed", "sentence", sentence.Text, "error", err)
}
}
+ case <-TTSFlushChan:
+ // lln is done get the whole message out
+ // FIXME: loses one token
+ for chunk := range TTSTextChan {
+ // orator.GetLogger().Info("flushing", "chunk", chunk)
+ // sentenceBuf.WriteString(chunk)
+ remainder.WriteString(chunk) // I get text here
+ if len(TTSTextChan) == 0 {
+ break
+ }
+ }
+ // Flush remaining text
+ remaining := remainder.String()
+ orator.GetLogger().Info("flushing", "rem", remaining)
+ if remaining != "" { // but nothing is here?
+ orator.GetLogger().Info("flushing", "remaining", remaining)
+ if err := orator.Speak(remaining); err != nil {
+ orator.GetLogger().Error("tts failed", "sentence", remaining, "error", err)
+ }
+ }
case <-TTSDoneChan:
// Flush remaining text
if remaining := sentenceBuf.String(); remaining != "" {