Force reinitialize when chat changed

2a3e71bf6e2eeb83fd13223f76104ef9164e25f7

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +8 -1Ignore whitespace
public/scripts/extensions/tts/index.js+8 -1
@@ -1,4 +1,4 @@
11import { cancelTtsPlay, eventSource, event_types, getCurrentChatId, isStreamingEnabled, name2, saveSettingsDebounced, substituteParams } from '../../../script.js';
22import { ModuleWorkerWrapper, doExtrasFetch, extension_settings, getApiUrl, getContext, modules, renderExtensionTemplateAsync } from '../../extensions.js';
33import { delay, escapeRegex, getBase64Async, getStringHash, onlyUnique } from '../../utils.js';
44import { EdgeTtsProvider } from './edge.js';
@@ -1022,11 +1022,18 @@ export async function initVoiceMap(unrestricted = false) {
10221022 }
10231023
10241024 currentInitVoiceMapPromise = (async () => {
1025+ const initialChatId = getCurrentChatId();
10251026 try {
10261027 await initVoiceMapInternal(unrestricted);
10271028 } finally {
10281029 currentInitVoiceMapPromise = null;
10291030 }
1031+ const currentChatId = getCurrentChatId();
1032+
1033+ if (initialChatId !== currentChatId) {
1034+ // Chat changed during initialization, reinitialize
1035+ await initVoiceMap(unrestricted);
1036+ }
10301037 })();
10311038
10321039 return currentInitVoiceMapPromise;