From 4f0935c4948cbb35618732782545d244382424c2 Mon Sep 17 00:00:00 2001 From: smirgol <14124899+smirgol@users.noreply.github.com> Date: Wed, 8 Nov 2023 19:08:42 +0100 Subject: [PATCH] better deep clone of message object. re-initalize ttsLastMessage after changing chats --- public/scripts/extensions/tts/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/public/scripts/extensions/tts/index.js b/public/scripts/extensions/tts/index.js index 89dbf8496..674c7a54f 100644 --- a/public/scripts/extensions/tts/index.js +++ b/public/scripts/extensions/tts/index.js @@ -145,7 +145,7 @@ async function moduleWorker() { } // clone message object, as things go haywire if message object is altered below (it's passed by reference) - const message = JSON.parse(JSON.stringify(chat[chat.length - 1])) + const message = structuredClone(chat[chat.length - 1]) // if last message within current message, message got extended. only send diff to TTS. if (ttsLastMessage !== null && message.mes.indexOf(ttsLastMessage) !== -1) { @@ -646,6 +646,7 @@ export function saveTtsProviderSettings() { async function onChatChanged() { await resetTtsPlayback() await initVoiceMap() + ttsLastMessage = null } async function onChatDeleted() {