mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Add provider-specific TTS processing: XTTS - replace ellipsis, Novel - remove tildes.
This commit is contained in:
@ -503,6 +503,10 @@ async function processTtsQueue() {
|
|||||||
text = matches ? matches.join(partJoiner) : text;
|
text = matches ? matches.join(partJoiner) : text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (typeof ttsProvider?.processText === 'function') {
|
||||||
|
text = await ttsProvider.processText(text);
|
||||||
|
}
|
||||||
|
|
||||||
// Collapse newlines and spaces into single space
|
// Collapse newlines and spaces into single space
|
||||||
text = text.replace(/\s+/g, ' ');
|
text = text.replace(/\s+/g, ' ');
|
||||||
|
|
||||||
|
@ -19,6 +19,17 @@ class NovelTtsProvider {
|
|||||||
customVoices: []
|
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() {
|
get settingsHtml() {
|
||||||
let html = `
|
let html = `
|
||||||
<div class="novel_tts_hints">
|
<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.
|
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
|
### class YourTtsProvider
|
||||||
#### Required
|
#### Required
|
||||||
Exported for use in extension index.js, and added to providers list in index.js
|
Exported for use in extension index.js, and added to providers list in index.js
|
||||||
1. generateTts(text, voiceId)
|
1. generateTts(text, voiceId)
|
||||||
2. fetchTtsVoiceObjects()
|
2. fetchTtsVoiceObjects()
|
||||||
@ -13,8 +13,9 @@ Exported for use in extension index.js, and added to providers list in index.js
|
|||||||
7. settingsHtml field
|
7. settingsHtml field
|
||||||
|
|
||||||
#### Optional
|
#### Optional
|
||||||
1. previewTtsVoice()
|
1. previewTtsVoice()
|
||||||
2. separator field
|
2. separator field
|
||||||
|
3. processText(text)
|
||||||
|
|
||||||
# Requirement Descriptions
|
# Requirement Descriptions
|
||||||
### generateTts(text, voiceId)
|
### 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.
|
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)
|
### loadSettings(settingsObject)
|
||||||
Required.
|
Required.
|
||||||
Handle the input settings from the TTS extension on provider load.
|
Handle the input settings from the TTS extension on provider load.
|
||||||
Put code in here to load your provider settings.
|
Put code in here to load your provider settings.
|
||||||
|
|
||||||
### settings field
|
### settings field
|
||||||
Required, used for storing any provider state that needs to be saved.
|
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)`.
|
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
|
### settingsHtml field
|
||||||
Required, injected into the TTS extension UI. Besides adding it, not relied on by TTS extension directly.
|
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
|
### separator field
|
||||||
Optional.
|
Optional.
|
||||||
Used when narrate quoted text is enabled.
|
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 = []
|
voices = []
|
||||||
separator = '. '
|
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 = {
|
languageLabels = {
|
||||||
"Arabic": "ar",
|
"Arabic": "ar",
|
||||||
"Brazilian Portuguese": "pt",
|
"Brazilian Portuguese": "pt",
|
||||||
|
Reference in New Issue
Block a user