This commit is contained in:
Timothy Jaeryang Baek 2026-08-24 06:26:49 -04:00
parent ef455fcef9
commit 495296346e

View file

@ -1896,31 +1896,38 @@
return;
}
const ttsSplitOn = $config?.audio?.tts?.split_on ?? 'punctuation';
const messageContentParts = getMessageContentParts(
getOutputText(message?.output) || removeAllDetails(message?.content ?? ''),
$config?.audio?.tts?.split_on ?? 'punctuation'
ttsSplitOn
);
if (!final) {
messageContentParts.pop();
}
const nextContentPart = messageContentParts.at(-1) ?? '';
if (!nextContentPart || (!final && nextContentPart === message.lastSentence)) {
return;
}
if (!final) {
message.lastSentence = nextContentPart;
}
eventTarget.dispatchEvent(
new CustomEvent('chat', {
detail: {
id: message.id,
content: nextContentPart
}
})
const sentContentPartCount = message.ttsSentContentPartCount ?? 0;
const nextContentParts = (final ? messageContentParts : messageContentParts.slice(0, -1)).slice(
sentContentPartCount
);
const pendingContentPartIndex = nextContentParts.findIndex(
(content) =>
!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(
new CustomEvent('chat', {
detail: {
id: message.id,
content
}
})
);
});
message.ttsSentContentPartCount = sentContentPartCount + dispatchContentParts.length;
};
const getContents = () => {