Force reinitialize when chat changed
| @@ -1,4 +1,4 @@ | ||
| 1 | 1 | import { cancelTtsPlay, eventSource, event_types, getCurrentChatId, isStreamingEnabled, name2, saveSettingsDebounced, substituteParams } from '../../../script.js'; |
| 2 | 2 | import { ModuleWorkerWrapper, doExtrasFetch, extension_settings, getApiUrl, getContext, modules, renderExtensionTemplateAsync } from '../../extensions.js'; |
| 3 | 3 | import { delay, escapeRegex, getBase64Async, getStringHash, onlyUnique } from '../../utils.js'; |
| 4 | 4 | import { EdgeTtsProvider } from './edge.js'; |
| @@ -1022,11 +1022,18 @@ export async function initVoiceMap(unrestricted = false) { | ||
| 1022 | 1022 | } |
| 1023 | 1023 | |
| 1024 | 1024 | currentInitVoiceMapPromise = (async () => { |
| 1025 | + const initialChatId = getCurrentChatId(); | |
| 1025 | 1026 | try { |
| 1026 | 1027 | await initVoiceMapInternal(unrestricted); |
| 1027 | 1028 | } finally { |
| 1028 | 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 | })(); |
| 1031 | 1038 | |
| 1032 | 1039 | return currentInitVoiceMapPromise; |