From 2a3e71bf6e2eeb83fd13223f76104ef9164e25f7 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sun, 30 Jun 2024 14:06:31 +0300 Subject: [PATCH] Force reinitialize when chat changed --- public/scripts/extensions/tts/index.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/public/scripts/extensions/tts/index.js b/public/scripts/extensions/tts/index.js index fab1fe96f..9f88fc5d1 100644 --- a/public/scripts/extensions/tts/index.js +++ b/public/scripts/extensions/tts/index.js @@ -1,4 +1,4 @@ -import { cancelTtsPlay, eventSource, event_types, isStreamingEnabled, name2, saveSettingsDebounced, substituteParams } from '../../../script.js'; +import { cancelTtsPlay, eventSource, event_types, getCurrentChatId, isStreamingEnabled, name2, saveSettingsDebounced, substituteParams } from '../../../script.js'; import { ModuleWorkerWrapper, doExtrasFetch, extension_settings, getApiUrl, getContext, modules, renderExtensionTemplateAsync } from '../../extensions.js'; import { delay, escapeRegex, getBase64Async, getStringHash, onlyUnique } from '../../utils.js'; import { EdgeTtsProvider } from './edge.js'; @@ -1022,11 +1022,18 @@ export async function initVoiceMap(unrestricted = false) { } currentInitVoiceMapPromise = (async () => { + const initialChatId = getCurrentChatId(); try { await initVoiceMapInternal(unrestricted); } finally { currentInitVoiceMapPromise = null; } + const currentChatId = getCurrentChatId(); + + if (initialChatId !== currentChatId) { + // Chat changed during initialization, reinitialize + await initVoiceMap(unrestricted); + } })(); return currentInitVoiceMapPromise;