diff --git a/public/index.html b/public/index.html index 28d41d52d..895ba3c8a 100644 --- a/public/index.html +++ b/public/index.html @@ -4274,6 +4274,7 @@ Logic diff --git a/public/scripts/extensions/tts/index.js b/public/scripts/extensions/tts/index.js index e4f7a0a91..44b388cbc 100644 --- a/public/scripts/extensions/tts/index.js +++ b/public/scripts/extensions/tts/index.js @@ -1,6 +1,6 @@ import { callPopup, cancelTtsPlay, eventSource, event_types, name2, saveSettingsDebounced } from '../../../script.js'; import { ModuleWorkerWrapper, doExtrasFetch, extension_settings, getApiUrl, getContext, modules } from '../../extensions.js'; -import { delay, escapeRegex, getStringHash } from '../../utils.js'; +import { delay, escapeRegex, getStringHash, onlyUnique } from '../../utils.js'; import { EdgeTtsProvider } from './edge.js'; import { ElevenLabsTtsProvider } from './elevenlabs.js'; import { SileroTtsProvider } from './silerotts.js'; @@ -463,13 +463,25 @@ function saveLastValues() { } async function tts(text, voiceId, char) { + async function processResponse(response) { + // RVC injection + if (extension_settings.rvc.enabled && typeof window['rvcVoiceConversion'] === 'function') + response = await window['rvcVoiceConversion'](response, char, text); + + await addAudioJob(response); + } + let response = await ttsProvider.generateTts(text, voiceId); - // RVC injection - if (extension_settings.rvc.enabled && typeof window['rvcVoiceConversion'] === 'function') - response = await window['rvcVoiceConversion'](response, char, text); + // If async generator, process every chunk as it comes in + if (typeof response[Symbol.asyncIterator] === 'function') { + for await (const chunk of response) { + await processResponse(chunk); + } + } else { + await processResponse(response); + } - addAudioJob(response); completeTtsJob(); } @@ -733,7 +745,7 @@ function getCharacters(unrestricted) { if (unrestricted) { const names = context.characters.map(char => char.name); names.unshift(DEFAULT_VOICE_MARKER); - return names; + return names.filter(onlyUnique); } let characters = []; @@ -748,14 +760,13 @@ function getCharacters(unrestricted) { characters.push(context.name1); const group = context.groups.find(group => context.groupId == group.id); for (let member of group.members) { - // Remove suffix - if (member.endsWith('.png')) { - member = member.slice(0, -4); + const character = context.characters.find(char => char.avatar == member); + if (character) { + characters.push(character.name); } - characters.push(member); } } - return characters; + return characters.filter(onlyUnique); } function sanitizeId(input) { diff --git a/public/scripts/extensions/tts/novel.js b/public/scripts/extensions/tts/novel.js index 62a6dd9ad..7c89c889a 100644 --- a/public/scripts/extensions/tts/novel.js +++ b/public/scripts/extensions/tts/novel.js @@ -1,4 +1,5 @@ import { getRequestHeaders, callPopup } from '../../../script.js'; +import { splitRecursive } from '../../utils.js'; import { getPreviewString, saveTtsProviderSettings } from './index.js'; import { initVoiceMap } from './index.js'; @@ -52,7 +53,7 @@ class NovelTtsProvider { // Add a new Novel custom voice to provider - async addCustomVoice(){ + async addCustomVoice() { const voiceName = await callPopup('

Custom Voice name:

', 'input'); this.settings.customVoices.push(voiceName); this.populateCustomVoices(); @@ -74,7 +75,7 @@ class NovelTtsProvider { } // Create the UI dropdown list of voices in provider - populateCustomVoices(){ + populateCustomVoices() { let voiceSelect = $('#tts-novel-custom-voices-select'); voiceSelect.empty(); this.settings.customVoices.forEach(voice => { @@ -88,7 +89,7 @@ class NovelTtsProvider { console.info('Using default TTS Provider settings'); } $('#tts-novel-custom-voices-add').on('click', () => (this.addCustomVoice())); - $('#tts-novel-custom-voices-delete').on('click',() => (this.deleteCustomVoice())); + $('#tts-novel-custom-voices-delete').on('click', () => (this.deleteCustomVoice())); // Only accept keys defined in defaultSettings this.settings = this.defaultSettings; @@ -108,7 +109,7 @@ class NovelTtsProvider { // Perform a simple readiness check by trying to fetch voiceIds // Doesnt really do much for Novel, not seeing a good way to test this at the moment. - async checkReady(){ + async checkReady() { await this.fetchTtsVoiceObjects(); } @@ -179,22 +180,26 @@ class NovelTtsProvider { this.audioElement.play(); } - async fetchTtsGeneration(inputText, voiceId) { + async* fetchTtsGeneration(inputText, voiceId) { + const MAX_LENGTH = 1000; console.info(`Generating new TTS for voice_id ${voiceId}`); - const response = await fetch('/api/novelai/generate-voice', - { - method: 'POST', - headers: getRequestHeaders(), - body: JSON.stringify({ - 'text': inputText, - 'voice': voiceId, - }), - }, - ); - if (!response.ok) { - toastr.error(response.statusText, 'TTS Generation Failed'); - throw new Error(`HTTP ${response.status}: ${await response.text()}`); + const chunks = splitRecursive(inputText, MAX_LENGTH); + for (const chunk of chunks) { + const response = await fetch('/api/novelai/generate-voice', + { + method: 'POST', + headers: getRequestHeaders(), + body: JSON.stringify({ + 'text': chunk, + 'voice': voiceId, + }), + }, + ); + if (!response.ok) { + toastr.error(response.statusText, 'TTS Generation Failed'); + throw new Error(`HTTP ${response.status}: ${await response.text()}`); + } + yield response; } - return response; } } diff --git a/public/scripts/world-info.js b/public/scripts/world-info.js index a33283b8e..67ed6a9ee 100644 --- a/public/scripts/world-info.js +++ b/public/scripts/world-info.js @@ -39,6 +39,7 @@ const world_info_logic = { AND_ANY: 0, NOT_ALL: 1, NOT_ANY: 2, + AND_ALL: 3, }; let world_info = {}; @@ -1789,6 +1790,7 @@ async function checkWorldInfo(chat, maxContext) { ) { console.debug(`WI UID:${entry.uid} found. Checking logic: ${entry.selectiveLogic}`); let hasAnyMatch = false; + let hasAllMatch = true; secondary: for (let keysecondary of entry.keysecondary) { const secondarySubstituted = substituteParams(keysecondary); const hasSecondaryMatch = secondarySubstituted && matchKeys(textToScan, secondarySubstituted.trim()); @@ -1798,6 +1800,10 @@ async function checkWorldInfo(chat, maxContext) { hasAnyMatch = true; } + if (!hasSecondaryMatch) { + hasAllMatch = false; + } + // Simplified AND ANY / NOT ALL if statement. (Proper fix for PR#1356 by Bronya) // If AND ANY logic and the main checks pass OR if NOT ALL logic and the main checks do not pass if ((selectiveLogic === world_info_logic.AND_ANY && hasSecondaryMatch) || (selectiveLogic === world_info_logic.NOT_ALL && !hasSecondaryMatch)) { @@ -1817,6 +1823,12 @@ async function checkWorldInfo(chat, maxContext) { console.debug(`(NOT ANY Check) Activating WI Entry ${entry.uid}, no secondary keywords found.`); activatedNow.add(entry); } + + // Handle AND ALL logic + if (selectiveLogic === world_info_logic.AND_ALL && hasAllMatch) { + console.debug(`(AND ALL Check) Activating WI Entry ${entry.uid}, all secondary keywords found.`); + activatedNow.add(entry); + } } else { // Handle cases where secondary is empty console.debug(`WI UID ${entry.uid}: Activated without filter logic.`); diff --git a/src/endpoints/novelai.js b/src/endpoints/novelai.js index f38f4cf7f..c26fa6f15 100644 --- a/src/endpoints/novelai.js +++ b/src/endpoints/novelai.js @@ -342,7 +342,9 @@ router.post('/generate-voice', jsonParser, async (request, response) => { }); if (!result.ok) { - return response.sendStatus(result.status); + const errorText = await result.text(); + console.log('NovelAI returned an error.', result.statusText, errorText); + return response.sendStatus(500); } const chunks = await readAllChunks(result.body);