add missing session handling to silerotts

This commit is contained in:
smirgol
2023-10-29 17:18:21 +01:00
parent 97b9d99503
commit b46f89b345

View File

@ -32,6 +32,7 @@ class SileroTtsProvider {
// Used when provider settings are updated from UI // Used when provider settings are updated from UI
this.settings.provider_endpoint = $('#silero_tts_endpoint').val() this.settings.provider_endpoint = $('#silero_tts_endpoint').val()
saveTtsProviderSettings() saveTtsProviderSettings()
this.refreshSession()
} }
async loadSettings(settings) { async loadSettings(settings) {
@ -64,6 +65,7 @@ class SileroTtsProvider {
$('#silero_tts_endpoint').val(this.settings.provider_endpoint) $('#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() await this.checkReady()
@ -78,6 +80,10 @@ class SileroTtsProvider {
async onRefreshClick() { async onRefreshClick() {
return return
} }
async refreshSession() {
await this.initSession()
}
//#################// //#################//
// TTS Interfaces // // TTS Interfaces //
@ -125,7 +131,8 @@ class SileroTtsProvider {
}, },
body: JSON.stringify({ body: JSON.stringify({
"text": inputText, "text": inputText,
"speaker": voiceId "speaker": voiceId,
"session": "sillytavern"
}) })
} }
) )
@ -135,6 +142,29 @@ class SileroTtsProvider {
} }
return response 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 // Interface not used by Silero TTS
async fetchTtsFromHistory(history_item_id) { async fetchTtsFromHistory(history_item_id) {