From 66f86062b81bcfbf831ec084a93577cb7fb19c25 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sat, 10 Feb 2024 19:33:29 -0800 Subject: [PATCH] feat: merge one word sentence --- .../chat/Messages/ResponseMessage.svelte | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/lib/components/chat/Messages/ResponseMessage.svelte b/src/lib/components/chat/Messages/ResponseMessage.svelte index 7ea449505..06229769d 100644 --- a/src/lib/components/chat/Messages/ResponseMessage.svelte +++ b/src/lib/components/chat/Messages/ResponseMessage.svelte @@ -151,7 +151,22 @@ if ($settings?.speech?.engine === 'openai') { loadingSpeech = true; - const sentences = extractSentences(message.content); + const sentences = extractSentences(message.content).reduce((mergedTexts, currentText) => { + const lastIndex = mergedTexts.length - 1; + if (lastIndex >= 0) { + const previousText = mergedTexts[lastIndex]; + const wordCount = previousText.split(/\s+/).length; + if (wordCount < 2) { + mergedTexts[lastIndex] = previousText + ' ' + currentText; + } else { + mergedTexts.push(currentText); + } + } else { + mergedTexts.push(currentText); + } + return mergedTexts; + }, []); + console.log(sentences); sentencesAudio = sentences.reduce((a, e, i, arr) => {