mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-01-05 13:36:47 +01:00
Add provider-specific TTS processing: XTTS - replace ellipsis, Novel - remove tildes.
This commit is contained in:
parent
edafb8dd13
commit
ffc4f22012
@ -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, ' ');
|
||||
|
||||
|
@ -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">
|
||||
|
@ -1,8 +1,8 @@
|
||||
# Provider Requirements.
|
||||
# Provider Requirements.
|
||||
Because I don't know how, or if you can, and/or maybe I am just too lazy to implement interfaces in JS, here's the requirements of a provider that the extension needs to operate.
|
||||
|
||||
### class YourTtsProvider
|
||||
#### Required
|
||||
#### Required
|
||||
Exported for use in extension index.js, and added to providers list in index.js
|
||||
1. generateTts(text, voiceId)
|
||||
2. fetchTtsVoiceObjects()
|
||||
@ -13,8 +13,9 @@ Exported for use in extension index.js, and added to providers list in index.js
|
||||
7. settingsHtml field
|
||||
|
||||
#### Optional
|
||||
1. previewTtsVoice()
|
||||
1. previewTtsVoice()
|
||||
2. separator field
|
||||
3. processText(text)
|
||||
|
||||
# Requirement Descriptions
|
||||
### generateTts(text, voiceId)
|
||||
@ -49,14 +50,14 @@ Return without error to let TTS extension know that the provider is ready.
|
||||
Return an error to block the main TTS extension for initializing the provider and UI. The error will be put in the TTS extension UI directly.
|
||||
|
||||
### loadSettings(settingsObject)
|
||||
Required.
|
||||
Required.
|
||||
Handle the input settings from the TTS extension on provider load.
|
||||
Put code in here to load your provider settings.
|
||||
|
||||
### settings field
|
||||
Required, used for storing any provider state that needs to be saved.
|
||||
Anything stored in this field is automatically persisted under extension_settings[providerName] by the main extension in `saveTtsProviderSettings()`, as well as loaded when the provider is selected in `loadTtsProvider(provider)`.
|
||||
TTS extension doesn't expect any specific contents.
|
||||
TTS extension doesn't expect any specific contents.
|
||||
|
||||
### settingsHtml field
|
||||
Required, injected into the TTS extension UI. Besides adding it, not relied on by TTS extension directly.
|
||||
@ -68,4 +69,8 @@ Function to handle playing previews of voice samples if no direct preview_url is
|
||||
### separator field
|
||||
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 `...`
|
||||
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.
|
||||
|
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user