refac
This commit is contained in:
1 parent
ef455fcef9
commit
495296346e
1 file changed
+27
-20
@@ -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
|
||||||
}
|
|
||||||
|
|
||||||
if (!final) {
|
|
||||||
message.lastSentence = nextContentPart;
|
|
||||||
}
|
|
||||||
|
|
||||||
eventTarget.dispatchEvent(
|
|
||||||
new CustomEvent('chat', {
|
|
||||||
detail: {
|
|
||||||
id: message.id,
|
|
||||||
content: nextContentPart
|
|
||||||
}
|
|
||||||
})
|
|
||||||
);
|
);
|
||||||
|
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 = () => {
|
const getContents = () => {
|
||||||
|
|||||||
Reference in new issue
Block a user