Remove char name from the TTS if it is hidden from display with power user setting

This commit is contained in:
Cohee
2023-06-15 15:04:09 +03:00
parent 2f6ed2c91c
commit 8e468908c0
2 changed files with 13 additions and 1 deletions

View File

@ -1,12 +1,13 @@
import { callPopup, cancelTtsPlay, eventSource, event_types, isMultigenEnabled, is_send_press, saveSettingsDebounced } from '../../../script.js'
import { ModuleWorkerWrapper, extension_settings, getContext } from '../../extensions.js'
import { getStringHash } from '../../utils.js'
import { escapeRegex, getStringHash } from '../../utils.js'
import { EdgeTtsProvider } from './edge.js'
import { ElevenLabsTtsProvider } from './elevenlabs.js'
import { SileroTtsProvider } from './silerotts.js'
import { SystemTtsProvider } from './system.js'
import { NovelTtsProvider } from './novel.js'
import { isMobile } from '../../RossAscends-mods.js'
import { power_user } from '../../power-user.js'
const UPDATE_INTERVAL = 1000
@ -409,6 +410,13 @@ async function processTtsQueue() {
console.log(`TTS: ${text}`)
const char = currentTtsJob.name
// Remove character name from start of the line if power user setting is disabled
if (char && !power_user.allow_name2_display) {
debugger;
const escapedChar = escapeRegex(char);
text = text.replace(new RegExp(`^${escapedChar}:`, 'gm'), '');
}
try {
if (!text) {
console.warn('Got empty text in TTS queue job.');

View File

@ -431,3 +431,7 @@ export function getCharaFilename() {
return fileName.replace(/\.[^/.]+$/, "")
}
}
export function escapeRegex(string) {
return string.replace(/[/\-\\^$*+?.()|[\]{}]/g, '\\$&');
}