This commit is contained in:
Timothy Jaeryang Baek committed 2026-08-24 06:26:49 -04:00
1 parent ef455fcef9
commit 495296346e
1 file changed
+20 -13
+20 -13
View File
@@ -1896,31 +1896,38 @@
return; return;
} }
const ttsSplitOn = $config?.audio?.tts?.split_on ?? 'punctuation';
const messageContentParts = getMessageContentParts( const messageContentParts = getMessageContentParts(
getOutputText(message?.output) || removeAllDetails(message?.content ?? ''), getOutputText(message?.output) || removeAllDetails(message?.content ?? ''),
$config?.audio?.tts?.split_on ?? 'punctuation' ttsSplitOn
); );
if (!final) {
messageContentParts.pop();
}
const nextContentPart = messageContentParts.at(-1) ?? ''; const sentContentPartCount = message.ttsSentContentPartCount ?? 0;
if (!nextContentPart || (!final && nextContentPart === message.lastSentence)) { const nextContentParts = (final ? messageContentParts : messageContentParts.slice(0, -1)).slice(
return; sentContentPartCount
} );
const pendingContentPartIndex = nextContentParts.findIndex(
if (!final) { (content) =>
message.lastSentence = nextContentPart; !final &&
} ttsSplitOn === 'punctuation' &&
(content.split(/\s+/).length < 4 || content.length < 50)
);
const dispatchContentParts =
pendingContentPartIndex === -1
? nextContentParts
: nextContentParts.slice(0, pendingContentPartIndex);
dispatchContentParts.forEach((content) => {
eventTarget.dispatchEvent( eventTarget.dispatchEvent(
new CustomEvent('chat', { new CustomEvent('chat', {
detail: { detail: {
id: message.id, id: message.id,
content: nextContentPart content
} }
}) })
); );
});
message.ttsSentContentPartCount = sentContentPartCount + dispatchContentParts.length;
}; };
const getContents = () => { const getContents = () => {