Fix: tts skiping over sentences
This commit is contained in:
62
extra/tts.go
62
extra/tts.go
@@ -92,8 +92,6 @@ func (o *KokoroOrator) stoproutine() {
|
|||||||
|
|
||||||
func (o *KokoroOrator) readroutine() {
|
func (o *KokoroOrator) readroutine() {
|
||||||
tokenizer, _ := english.NewSentenceTokenizer(nil)
|
tokenizer, _ := english.NewSentenceTokenizer(nil)
|
||||||
// var sentenceBuf bytes.Buffer
|
|
||||||
// var remainder strings.Builder
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case chunk := <-TTSTextChan:
|
case chunk := <-TTSTextChan:
|
||||||
@@ -106,24 +104,28 @@ func (o *KokoroOrator) readroutine() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
text := o.textBuffer.String()
|
text := o.textBuffer.String()
|
||||||
o.mu.Unlock()
|
|
||||||
sentences := tokenizer.Tokenize(text)
|
sentences := tokenizer.Tokenize(text)
|
||||||
o.logger.Debug("adding chunk", "chunk", chunk, "text", text, "sen-len", len(sentences))
|
o.logger.Debug("adding chunk", "chunk", chunk, "text", text, "sen-len", len(sentences))
|
||||||
for i, sentence := range sentences {
|
if len(sentences) <= 1 {
|
||||||
if i == len(sentences)-1 { // last sentence
|
o.mu.Unlock()
|
||||||
o.mu.Lock()
|
continue
|
||||||
o.textBuffer.Reset()
|
}
|
||||||
_, err := o.textBuffer.WriteString(sentence.Text)
|
completeSentences := sentences[:len(sentences)-1]
|
||||||
o.mu.Unlock()
|
remaining := sentences[len(sentences)-1].Text
|
||||||
if err != nil {
|
o.textBuffer.Reset()
|
||||||
o.logger.Warn("failed to write to stringbuilder", "error", err)
|
o.textBuffer.WriteString(remaining)
|
||||||
continue
|
o.mu.Unlock()
|
||||||
}
|
|
||||||
continue // if only one (often incomplete) sentence; wait for next chunk
|
for _, sentence := range completeSentences {
|
||||||
|
o.mu.Lock()
|
||||||
|
interrupted := o.interrupt
|
||||||
|
o.mu.Unlock()
|
||||||
|
if interrupted {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
cleanedText := models.CleanText(sentence.Text)
|
cleanedText := models.CleanText(sentence.Text)
|
||||||
if cleanedText == "" {
|
if cleanedText == "" {
|
||||||
continue // Skip empty text after cleaning
|
continue
|
||||||
}
|
}
|
||||||
o.logger.Debug("calling Speak with sentence", "sent", cleanedText)
|
o.logger.Debug("calling Speak with sentence", "sent", cleanedText)
|
||||||
if err := o.Speak(cleanedText); err != nil {
|
if err := o.Speak(cleanedText); err != nil {
|
||||||
@@ -338,24 +340,28 @@ func (o *GoogleTranslateOrator) readroutine() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
text := o.textBuffer.String()
|
text := o.textBuffer.String()
|
||||||
o.mu.Unlock()
|
|
||||||
sentences := tokenizer.Tokenize(text)
|
sentences := tokenizer.Tokenize(text)
|
||||||
o.logger.Debug("adding chunk", "chunk", chunk, "text", text, "sen-len", len(sentences))
|
o.logger.Debug("adding chunk", "chunk", chunk, "text", text, "sen-len", len(sentences))
|
||||||
for i, sentence := range sentences {
|
if len(sentences) <= 1 {
|
||||||
if i == len(sentences)-1 { // last sentence
|
o.mu.Unlock()
|
||||||
o.mu.Lock()
|
continue
|
||||||
o.textBuffer.Reset()
|
}
|
||||||
_, err := o.textBuffer.WriteString(sentence.Text)
|
completeSentences := sentences[:len(sentences)-1]
|
||||||
o.mu.Unlock()
|
remaining := sentences[len(sentences)-1].Text
|
||||||
if err != nil {
|
o.textBuffer.Reset()
|
||||||
o.logger.Warn("failed to write to stringbuilder", "error", err)
|
o.textBuffer.WriteString(remaining)
|
||||||
continue
|
o.mu.Unlock()
|
||||||
}
|
|
||||||
continue // if only one (often incomplete) sentence; wait for next chunk
|
for _, sentence := range completeSentences {
|
||||||
|
o.mu.Lock()
|
||||||
|
interrupted := o.interrupt
|
||||||
|
o.mu.Unlock()
|
||||||
|
if interrupted {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
cleanedText := models.CleanText(sentence.Text)
|
cleanedText := models.CleanText(sentence.Text)
|
||||||
if cleanedText == "" {
|
if cleanedText == "" {
|
||||||
continue // Skip empty text after cleaning
|
continue
|
||||||
}
|
}
|
||||||
o.logger.Debug("calling Speak with sentence", "sent", cleanedText)
|
o.logger.Debug("calling Speak with sentence", "sent", cleanedText)
|
||||||
if err := o.Speak(cleanedText); err != nil {
|
if err := o.Speak(cleanedText); err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user