From b46f89b3459eff2351e3eace5d4bd2ee8c9020e5 Mon Sep 17 00:00:00 2001 From: smirgol <14124899+smirgol@users.noreply.github.com> Date: Sun, 29 Oct 2023 17:18:21 +0100 Subject: [PATCH 1/3] add missing session handling to silerotts --- public/scripts/extensions/tts/silerotts.js | 32 +++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/public/scripts/extensions/tts/silerotts.js b/public/scripts/extensions/tts/silerotts.js index 8d9120f08..70fa6020a 100644 --- a/public/scripts/extensions/tts/silerotts.js +++ b/public/scripts/extensions/tts/silerotts.js @@ -32,6 +32,7 @@ class SileroTtsProvider { // Used when provider settings are updated from UI this.settings.provider_endpoint = $('#silero_tts_endpoint').val() saveTtsProviderSettings() + this.refreshSession() } async loadSettings(settings) { @@ -64,6 +65,7 @@ class SileroTtsProvider { $('#silero_tts_endpoint').val(this.settings.provider_endpoint) $('#silero_tts_endpoint').on("input", () => {this.onSettingsChange()}) + this.refreshSession() await this.checkReady() @@ -78,6 +80,10 @@ class SileroTtsProvider { async onRefreshClick() { return } + + async refreshSession() { + await this.initSession() + } //#################// // TTS Interfaces // @@ -125,7 +131,8 @@ class SileroTtsProvider { }, body: JSON.stringify({ "text": inputText, - "speaker": voiceId + "speaker": voiceId, + "session": "sillytavern" }) } ) @@ -135,6 +142,29 @@ class SileroTtsProvider { } return response } + + async initSession() { + console.info(`requesting new session`) + const response = await doExtrasFetch( + `${this.settings.provider_endpoint}/init_session`, + { + method: 'POST', + headers: { + '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 + }, + body: JSON.stringify({ + "path": "sillytavern" + }) + } + ) + + if (!response.ok && response.status !== 404) { + toastr.error(response.statusText, 'Fetching Session Failed'); + throw new Error(`HTTP ${response.status}: ${await response.text()}`); + } + return response + } // Interface not used by Silero TTS async fetchTtsFromHistory(history_item_id) { From 3346420527ebd301babb5c8d1dcc543cf4e6497f Mon Sep 17 00:00:00 2001 From: smirgol <14124899+smirgol@users.noreply.github.com> Date: Sun, 29 Oct 2023 19:58:02 +0100 Subject: [PATCH 2/3] fix api endpoint to match the current definition --- public/scripts/extensions/tts/silerotts.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/scripts/extensions/tts/silerotts.js b/public/scripts/extensions/tts/silerotts.js index 70fa6020a..88f9f03c9 100644 --- a/public/scripts/extensions/tts/silerotts.js +++ b/public/scripts/extensions/tts/silerotts.js @@ -146,7 +146,7 @@ class SileroTtsProvider { async initSession() { console.info(`requesting new session`) const response = await doExtrasFetch( - `${this.settings.provider_endpoint}/init_session`, + `${this.settings.provider_endpoint}/session`, { method: 'POST', headers: { From 16527710b360cb8ff4d0f70422a8ab4cd9d4c191 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Tue, 28 Nov 2023 19:24:26 +0200 Subject: [PATCH 3/3] Make less obtrusive --- public/scripts/extensions/tts/silerotts.js | 56 +++++++++++----------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/public/scripts/extensions/tts/silerotts.js b/public/scripts/extensions/tts/silerotts.js index 88f9f03c9..f78a3314f 100644 --- a/public/scripts/extensions/tts/silerotts.js +++ b/public/scripts/extensions/tts/silerotts.js @@ -44,8 +44,8 @@ class SileroTtsProvider { // Only accept keys defined in defaultSettings this.settings = this.defaultSettings - for (const key in settings){ - if (key in this.settings){ + for (const key in settings) { + if (key in this.settings) { this.settings[key] = settings[key] } else { throw `Invalid setting passed to TTS Provider: ${key}` @@ -64,7 +64,7 @@ class SileroTtsProvider { }, 2000); $('#silero_tts_endpoint').val(this.settings.provider_endpoint) - $('#silero_tts_endpoint').on("input", () => {this.onSettingsChange()}) + $('#silero_tts_endpoint').on("input", () => { this.onSettingsChange() }) this.refreshSession() await this.checkReady() @@ -73,14 +73,14 @@ class SileroTtsProvider { } // Perform a simple readiness check by trying to fetch voiceIds - async checkReady(){ + async checkReady() { await this.fetchTtsVoiceObjects() } async onRefreshClick() { return } - + async refreshSession() { await this.initSession() } @@ -102,7 +102,7 @@ class SileroTtsProvider { return match } - async generateTts(text, voiceId){ + async generateTts(text, voiceId) { const response = await this.fetchTtsGeneration(text, voiceId) return response } @@ -127,7 +127,7 @@ class SileroTtsProvider { method: 'POST', headers: { '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({ "text": inputText, @@ -142,28 +142,30 @@ class SileroTtsProvider { } return response } - - async initSession() { - console.info(`requesting new session`) - const response = await doExtrasFetch( - `${this.settings.provider_endpoint}/session`, - { - method: 'POST', - headers: { - '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 - }, - body: JSON.stringify({ - "path": "sillytavern" - }) - } - ) - if (!response.ok && response.status !== 404) { - toastr.error(response.statusText, 'Fetching Session Failed'); - throw new Error(`HTTP ${response.status}: ${await response.text()}`); + async initSession() { + console.info(`Silero TTS: requesting new session`); + try { + const response = await doExtrasFetch( + `${this.settings.provider_endpoint}/session`, + { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'Cache-Control': 'no-cache', + }, + body: JSON.stringify({ + "path": "sillytavern", + }), + } + ) + + if (!response.ok && response.status !== 404) { + throw new Error(`HTTP ${response.status}: ${await response.text()}`); + } + } catch (error) { + console.info('Silero TTS: endpoint not available', error); } - return response } // Interface not used by Silero TTS