Add provider-specific TTS processing: XTTS - replace ellipsis, Novel - remove tildes.

This commit is contained in:
Cohee
2023-11-27 13:25:49 +02:00
parent edafb8dd13
commit ffc4f22012
4 changed files with 39 additions and 6 deletions

View File

@ -503,6 +503,10 @@ async function processTtsQueue() {
text = matches ? matches.join(partJoiner) : text;
}
if (typeof ttsProvider?.processText === 'function') {
text = await ttsProvider.processText(text);
}
// Collapse newlines and spaces into single space
text = text.replace(/\s+/g, ' ');

View File

@ -19,6 +19,17 @@ class NovelTtsProvider {
customVoices: []
}
/**
* Perform any text processing before passing to TTS engine.
* @param {string} text Input text
* @returns {string} Processed text
*/
processText(text) {
// Novel reads tilde as a word. Replace with full stop
text = text.replace(/~/g, '.');
return text;
}
get settingsHtml() {
let html = `
<div class="novel_tts_hints">

View File

@ -15,6 +15,7 @@ Exported for use in extension index.js, and added to providers list in index.js
#### Optional
1. previewTtsVoice()
2. separator field
3. processText(text)
# Requirement Descriptions
### generateTts(text, voiceId)
@ -69,3 +70,7 @@ Function to handle playing previews of voice samples if no direct preview_url is
Optional.
Used when narrate quoted text is enabled.
Defines the string of characters used to introduce separation between between the groups of extracted quoted text sent to the provider. The provider will use this to introduce pauses by default using `...`
### processText(text)
Optional.
A function applied to the input text before passing it to the TTS generator. Can be async.

View File

@ -13,6 +13,19 @@ class XTTSTtsProvider {
voices = []
separator = '. '
/**
* Perform any text processing before passing to TTS engine.
* @param {string} text Input text
* @returns {string} Processed text
*/
processText(text) {
// Replace fancy ellipsis with "..."
text = text.replace(/…/g, '...')
// Replace multiple "." with single "."
text = text.replace(/\.+/g, '.')
return text
}
languageLabels = {
"Arabic": "ar",
"Brazilian Portuguese": "pt",