feat: merge one word sentence

This commit is contained in:
Timothy J. Baek 2024-02-10 19:33:29 -08:00
parent f01428f502
commit 66f86062b8

View file

@ -151,7 +151,22 @@
if ($settings?.speech?.engine === 'openai') { if ($settings?.speech?.engine === 'openai') {
loadingSpeech = true; 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); console.log(sentences);
sentencesAudio = sentences.reduce((a, e, i, arr) => { sentencesAudio = sentences.reduce((a, e, i, arr) => {