Force reinitialize when chat changed

2a3e71bf6e2eeb83fd13223f76104ef9164e25f7

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

1 files changed, +8 -1Showing whitespace changes
public/scripts/extensions/tts/index.js+8 -1
@@ -1,4 +1,4 @@
1import { cancelTtsPlay, eventSource, event_types, isStreamingEnabled, name2, saveSettingsDebounced, substituteParams } from '../../../script.js';1import { cancelTtsPlay, eventSource, event_types, getCurrentChatId, isStreamingEnabled, name2, saveSettingsDebounced, substituteParams } from '../../../script.js';
2import { ModuleWorkerWrapper, doExtrasFetch, extension_settings, getApiUrl, getContext, modules, renderExtensionTemplateAsync } from '../../extensions.js';2import { ModuleWorkerWrapper, doExtrasFetch, extension_settings, getApiUrl, getContext, modules, renderExtensionTemplateAsync } from '../../extensions.js';
3import { delay, escapeRegex, getBase64Async, getStringHash, onlyUnique } from '../../utils.js';3import { delay, escapeRegex, getBase64Async, getStringHash, onlyUnique } from '../../utils.js';
4import { EdgeTtsProvider } from './edge.js';4import { EdgeTtsProvider } from './edge.js';
@@ -1022,11 +1022,18 @@ export async function initVoiceMap(unrestricted = false) {
1022 }1022 }
10231023
1024 currentInitVoiceMapPromise = (async () => {1024 currentInitVoiceMapPromise = (async () => {
1025 const initialChatId = getCurrentChatId();
1025 try {1026 try {
1026 await initVoiceMapInternal(unrestricted);1027 await initVoiceMapInternal(unrestricted);
1027 } finally {1028 } finally {
1028 currentInitVoiceMapPromise = null;1029 currentInitVoiceMapPromise = null;
1029 }1030 }
1031 const currentChatId = getCurrentChatId();
1032
1033 if (initialChatId !== currentChatId) {
1034 // Chat changed during initialization, reinitialize
1035 await initVoiceMap(unrestricted);
1036 }
1030 })();1037 })();
10311038
1032 return currentInitVoiceMapPromise;1039 return currentInitVoiceMapPromise;