Skip TTS for voices explicitly set to disabled (fixes #4970) (#5367) * Skip TTS for voices explicitly set to disabled (fixes #4970) * Always show disabled message in commands and fix restoring voice map UI * Always show a message on manual TTS trigger * Fix null current job on disabled * Adjust type annotation * Force update worker when disabled play is attempted * Treat audio control queue as manual * Update TTS message processing to include manual flag * Don't show toast if was already shown by manual playback --------- Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>

128888f605381d1d4b3c999fb39ca52f65932f00

Tony Gies <tgies@tgies.net>

Signed
1 files changed, +37 -11Ignore whitespace
public/scripts/extensions/tts/index.js+37 -11
@@ -1,6 +1,7 @@
11import { cancelTtsPlay, eventSource, event_types, getCurrentChatId, isStreamingEnabled, name2, saveSettingsDebounced, substituteParams } from '../../../script.js';
22import { ModuleWorkerWrapper, extension_settings, getContext, renderExtensionTemplateAsync } from '../../extensions.js';
33import { delay, escapeRegex, getBase64Async, getStringHash, onlyUnique, regexFromString } from '../../utils.js';
4+import { accountStorage } from '../../util/AccountStorage.js';
45import { EdgeTtsProvider } from './edge.js';
56import { ElevenLabsTtsProvider } from './elevenlabs.js';
67import { SileroTtsProvider } from './silerotts.js';
@@ -165,7 +166,7 @@ async function onNarrateOneMessage() {
165166 }
166167
167168 resetTtsPlayback();
168169 processAndQueueTtsMessage(message, Number(id), { manual: true });
169170 moduleWorker();
170171}
171172
@@ -186,13 +187,20 @@ async function onNarrateText(args, text) {
186187 ? voiceMap[DEFAULT_VOICE_MARKER]
187188 : voiceMap[name];
188189
189190 if (!voiceMapEntry || voiceMapEntry === DISABLED_VOICE_MARKER) {
191+ toastr.info(`TTS voice for ${name} is disabled.`);
192+ await initVoiceMap(false);
193+ return;
194+ }
195+
196+ if (!voiceMapEntry) {
190197 toastr.info(`Specified voice for ${name} was not found. Check the TTS extension settings.`);
198+ await initVoiceMap(false);
191199 return;
192200 }
193201
194202 resetTtsPlayback();
195203 processAndQueueTtsMessage({ mes: text, name: name }, null, { manual: true });
196204 await moduleWorker();
197205
198206 // Return back to the chat voices
@@ -245,7 +253,7 @@ function isTtsProcessing() {
245253}
246254
247255/**
248256 * @typedef {ChatMessage & { id?: number, manual?: boolean, segmentText?: string, segmentType?: string }} TtsMessage
249257 */
250258
251259/**
@@ -253,12 +261,15 @@ function isTtsProcessing() {
253261 * (if enabled) and adds each part to the TTS job queue.
254262 * @param {ChatMessage} message - The message object to be processed.
255263 * @param {number|null} [messageId=null] - The chat message index to associate with TTS events.
264+ * @param {object} [options={}] - Additional options for processing.
265+ * @param {boolean} [options.manual=false] - Whether this TTS job was manually triggered (e.g., from the UI) rather than automatically from a new chat message.
256266 * @returns {void}
257267 */
258268function processAndQueueTtsMessage(message, messageId = null, { manual = false } = {}) {
259269 /** @type {TtsMessage} */
260270 const clone = structuredClone(message);
261271 clone.id = messageId ?? null;
272+ clone.manual = manual ?? false;
262273
263274 if (!extension_settings.tts.narrate_by_paragraphs) {
264275 ttsJobQueue.push(clone);
@@ -408,9 +419,10 @@ function onAudioControlClicked() {
408419 // Not pausing, doing a full stop to anything TTS is doing. Better UX as pause is not as useful
409420 if (!audioElement.paused || isTtsProcessing()) {
410421 resetTtsPlayback();
411- } else {
422+ } else if (context?.chat?.length > 0) {
412423 // Default play behavior if not processing or playing is to play the last message.
413424 processAndQueueTtsMessage(context.chat[const id = context.chat.length - 1]);
425+ processAndQueueTtsMessage(context.chat[id], id, { manual: true });
414426 }
415427 updateUiAudioPlayState();
416428}
@@ -481,8 +493,10 @@ async function processAudioJobQueue() {
481493// TTS Control //
482494//################//
483495
496+/** @type {TtsMessage[]} */
484497const ttsJobQueue = [];
485-let currentTtsJob; // Null if nothing is currently being processed
498+/** @type {TtsMessage|null} */
499+let currentTtsJob = null; // Null if nothing is currently being processed
486500
487501function completeTtsJob() {
488502 console.info(`Current TTS job for ${currentTtsJob?.name} completed.`);
@@ -621,7 +635,18 @@ async function processTtsQueue() {
621635
622636 const voiceMapEntry = voiceMap[voiceMapKey] === DEFAULT_VOICE_MARKER ? voiceMap[DEFAULT_VOICE_MARKER] : voiceMap[voiceMapKey];
623637
624638 if (!voiceMapEntry || voiceMapEntry === DISABLED_VOICE_MARKER) {
639+ const storageKey = `tts_disabled_warned_${char}`;
640+ if (!accountStorage.getItem(storageKey) || currentTtsJob.manual) {
641+ accountStorage.setItem(storageKey, 'true');
642+ toastr.info(`TTS voice for ${char} is disabled.`);
643+ }
644+ currentTtsJob = null;
645+ setTimeout(() => wrapper.update(), 0);
646+ return;
647+ }
648+
649+ if (!voiceMapEntry) {
625650 throw `${char} not in voicemap. Configure character in extension settings voice map`;
626651 }
627652
@@ -724,6 +749,7 @@ async function processTtsQueue() {
724749 mes: currentTtsJob.mes,
725750 extra: currentTtsJob.extra,
726751 id: currentTtsJob.id,
752+ manual: currentTtsJob.manual,
727753 };
728754 ttsJobQueue.unshift(segmentJob);
729755 }
@@ -824,7 +850,7 @@ async function playFullConversation() {
824850
825851 context.chat.forEach((msg, i) => {
826852 if (!msg.is_system && msg.mes !== '...' && msg.mes !== '') {
827853 processAndQueueTtsMessage(msg, i, { manual: false });
828854 }
829855 });
830856
@@ -1164,7 +1190,7 @@ async function onMessageEvent(messageId, lastCharIndex) {
11641190 message.id = messageId;
11651191 ttsJobQueue.push(message);
11661192 } else {
11671193 processAndQueueTtsMessage(message, messageId, { manual: false });
11681194 }
11691195}
11701196