Fix xtts separator

This commit is contained in:
Cohee 2023-11-22 17:47:58 +02:00
parent 56b63c0e02
commit f802fe1797
2 changed files with 37 additions and 33 deletions

View File

@ -502,6 +502,10 @@ async function processTtsQueue() {
const partJoiner = (ttsProvider?.separator || ' ... '); const partJoiner = (ttsProvider?.separator || ' ... ');
text = matches ? matches.join(partJoiner) : text; text = matches ? matches.join(partJoiner) : text;
} }
// Collapse newlines and spaces into single space
text = text.replace(/\s+/g, ' ');
console.log(`TTS: ${text}`) console.log(`TTS: ${text}`)
const char = currentTtsJob.name const char = currentTtsJob.name

View File

@ -11,25 +11,25 @@ class XTTSTtsProvider {
settings settings
ready = false ready = false
voices = [] voices = []
separator = ' .. ' separator = '. '
languageLabels = { languageLabels = {
"Arabic": "ar", "Arabic": "ar",
"Brazilian Portuguese": "pt", "Brazilian Portuguese": "pt",
"Chinese": "zh-cn", "Chinese": "zh-cn",
"Czech": "cs", "Czech": "cs",
"Dutch": "nl", "Dutch": "nl",
"English": "en", "English": "en",
"French": "fr", "French": "fr",
"German": "de", "German": "de",
"Italian": "it", "Italian": "it",
"Polish": "pl", "Polish": "pl",
"Russian": "ru", "Russian": "ru",
"Spanish": "es", "Spanish": "es",
"Turkish": "tr", "Turkish": "tr",
"Japanese": "ja", "Japanese": "ja",
"Korean": "ko", "Korean": "ko",
"Hungarian": "hu" "Hungarian": "hu"
} }
defaultSettings = { defaultSettings = {
@ -38,15 +38,15 @@ class XTTSTtsProvider {
voiceMap: {} voiceMap: {}
} }
get settingsHtml() { get settingsHtml() {
let html = ` let html = `
<label for="xtts_api_language">Language</label> <label for="xtts_api_language">Language</label>
<select id="xtts_api_language">`; <select id="xtts_api_language">`;
for (let language in this.languageLabels) { for (let language in this.languageLabels) {
if(this.languageLabels[language] == this.settings?.language){ if (this.languageLabels[language] == this.settings?.language) {
html += `<option value="${this.languageLabels[language]}" selected="selected">${language}</option>`; html += `<option value="${this.languageLabels[language]}" selected="selected">${language}</option>`;
continue continue
} }
@ -54,20 +54,20 @@ class XTTSTtsProvider {
html += `<option value="${this.languageLabels[language]}">${language}</option>`; html += `<option value="${this.languageLabels[language]}">${language}</option>`;
} }
html += ` html += `
</select> </select>
<label for="xtts_tts_endpoint">Provider Endpoint:</label> <label for="xtts_tts_endpoint">Provider Endpoint:</label>
<input id="xtts_tts_endpoint" type="text" class="text_pole" maxlength="250" value="${this.defaultSettings.provider_endpoint}"/> <input id="xtts_tts_endpoint" type="text" class="text_pole" maxlength="250" value="${this.defaultSettings.provider_endpoint}"/>
`; `;
html += ` html += `
<span> <span>
<span>Use <a target="_blank" href="https://github.com/daswer123/xtts-api-server">XTTSv2 TTS Server</a>.</span> <span>Use <a target="_blank" href="https://github.com/daswer123/xtts-api-server">XTTSv2 TTS Server</a>.</span>
`; `;
return html; return html;
} }
onSettingsChange() { onSettingsChange() {
@ -86,8 +86,8 @@ class XTTSTtsProvider {
// Only accept keys defined in defaultSettings // Only accept keys defined in defaultSettings
this.settings = this.defaultSettings this.settings = this.defaultSettings
for (const key in settings){ for (const key in settings) {
if (key in this.settings){ if (key in this.settings) {
this.settings[key] = settings[key] this.settings[key] = settings[key]
} else { } else {
throw `Invalid setting passed to TTS Provider: ${key}` throw `Invalid setting passed to TTS Provider: ${key}`
@ -106,9 +106,9 @@ class XTTSTtsProvider {
}, 2000); }, 2000);
$('#xtts_tts_endpoint').val(this.settings.provider_endpoint) $('#xtts_tts_endpoint').val(this.settings.provider_endpoint)
$('#xtts_tts_endpoint').on("input", () => {this.onSettingsChange()}) $('#xtts_tts_endpoint').on("input", () => { this.onSettingsChange() })
$('#xtts_api_language').val(this.settings.language) $('#xtts_api_language').val(this.settings.language)
$('#xtts_api_language').on("change", () => {this.onSettingsChange()}) $('#xtts_api_language').on("change", () => { this.onSettingsChange() })
await this.checkReady() await this.checkReady()
@ -116,8 +116,8 @@ class XTTSTtsProvider {
} }
// Perform a simple readiness check by trying to fetch voiceIds // Perform a simple readiness check by trying to fetch voiceIds
async checkReady(){ async checkReady() {
const response = await this.fetchTtsVoiceObjects() const response = await this.fetchTtsVoiceObjects()
} }
@ -142,7 +142,7 @@ class XTTSTtsProvider {
return match return match
} }
async generateTts(text, voiceId){ async generateTts(text, voiceId) {
const response = await this.fetchTtsGeneration(text, voiceId) const response = await this.fetchTtsGeneration(text, voiceId)
return response return response
} }
@ -167,7 +167,7 @@ class XTTSTtsProvider {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'Cache-Control': 'no-cache' // Added this line to disable caching of file so new files are always played - Rolyat 7/7/23 'Cache-Control': 'no-cache' // Added this line to disable caching of file so new files are always played - Rolyat 7/7/23
}, },
body: JSON.stringify({ body: JSON.stringify({
"text": inputText, "text": inputText,