From bf88829b03b330a6d02a18e7317d9acbf61deefc Mon Sep 17 00:00:00 2001 From: LenAnderson Date: Sun, 10 Dec 2023 16:32:10 +0000 Subject: [PATCH] add option to skip codeblock narration --- public/scripts/extensions/tts/index.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/public/scripts/extensions/tts/index.js b/public/scripts/extensions/tts/index.js index 9ae47750b..eb3a25da1 100644 --- a/public/scripts/extensions/tts/index.js +++ b/public/scripts/extensions/tts/index.js @@ -482,6 +482,12 @@ async function processTtsQueue() { console.debug('New message found, running TTS'); currentTtsJob = ttsJobQueue.shift(); let text = extension_settings.tts.narrate_translated_only ? (currentTtsJob?.extra?.display_text || currentTtsJob.mes) : currentTtsJob.mes; + + if (extension_settings.tts.skip_codeblocks) { + text = text.replace(/^\s{4}.*$/gm, '').trim(); + text = text.replace(/```.*?```/gs, '').trim(); + } + text = extension_settings.tts.narrate_dialogues_only ? text.replace(/\*[^*]*?(\*|$)/g, '').trim() // remove asterisks content : text.replaceAll('*', '').trim(); // remove just the asterisks @@ -639,6 +645,11 @@ function onNarrateTranslatedOnlyClick() { saveSettingsDebounced(); } +function onSkipCodeblocksClick() { + extension_settings.tts.skip_codeblocks = !!$('#tts_skip_codeblocks').prop('checked'); + saveSettingsDebounced(); +} + //##############// // TTS Provider // //##############// @@ -952,6 +963,10 @@ $(document).ready(function () { Narrate only the translated text +
@@ -972,6 +987,7 @@ $(document).ready(function () { $('#tts_narrate_dialogues').on('click', onNarrateDialoguesClick); $('#tts_narrate_quoted').on('click', onNarrateQuotedClick); $('#tts_narrate_translated_only').on('click', onNarrateTranslatedOnlyClick); + $('#tts_skip_codeblocks').on('click', onSkipCodeblocksClick); $('#tts_auto_generation').on('click', onAutoGenerationClick); $('#tts_narrate_user').on('click', onNarrateUserClick); $('#tts_voices').on('click', onTtsVoicesClick);