From 3643bc58f25571f97e9f52c018e725b8fcf527d3 Mon Sep 17 00:00:00 2001 From: Sanskar Tiwari Date: Sat, 13 May 2023 14:46:23 +0530 Subject: [PATCH 1/2] added the ability to speak only quoted text --- public/scripts/extensions/tts/index.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/public/scripts/extensions/tts/index.js b/public/scripts/extensions/tts/index.js index ae4818ef6..347e27c61 100644 --- a/public/scripts/extensions/tts/index.js +++ b/public/scripts/extensions/tts/index.js @@ -241,9 +241,16 @@ async function processTtsQueue() { console.debug('New message found, running TTS') currentTtsJob = ttsJobQueue.shift() - const text = extension_settings.tts.narrate_dialogues_only + let text = extension_settings.tts.narrate_dialogues_only ? currentTtsJob.mes.replace(/\*[^\*]*?(\*|$)/g, '').trim() // remove asterisks content : currentTtsJob.mes.replaceAll('*', '').trim() // remove just the asterisks + + if (extension_settings.tts.narrate_quoted_only) { + // narrate only the text inside double quotes + const matches = text.match(/".*?"/g); // Matches text inside double quotes, non-greedily + text = matches ? matches.join(' ... ... ... ') : text; + } + console.log(`TTS: ${text}`) const char = currentTtsJob.name try { @@ -288,6 +295,7 @@ function loadSettings() { extension_settings.tts.enabled ) $('#tts_narrate_dialogues').prop('checked', extension_settings.tts.narrate_dialogues_only) + $('#tts_narrate_quoted').prop('checked', extension_settings.tts.narrate_quoted_only) } const defaultSettings = { @@ -380,6 +388,13 @@ function onNarrateDialoguesClick() { saveSettingsDebounced() } + +function onNarrateQuotedClick() { + extension_settings.tts.narrate_quoted_only = $('#tts_narrate_quoted').prop('checked'); + saveSettingsDebounced() +} + + //##############// // TTS Provider // //##############// @@ -459,6 +474,10 @@ $(document).ready(function () { Narrate dialogues only +