mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-03-12 01:50:11 +01:00
Merge pull request #1299 from smirgol/silerott-add-session-handling
add missing session handling to SileroTTS
This commit is contained in:
commit
10249aae5a
@ -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) {
|
||||||
@ -43,8 +44,8 @@ class SileroTtsProvider {
|
|||||||
// 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}`
|
||||||
@ -63,7 +64,8 @@ class SileroTtsProvider {
|
|||||||
}, 2000);
|
}, 2000);
|
||||||
|
|
||||||
$('#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()
|
||||||
|
|
||||||
@ -71,7 +73,7 @@ class SileroTtsProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Perform a simple readiness check by trying to fetch voiceIds
|
// Perform a simple readiness check by trying to fetch voiceIds
|
||||||
async checkReady(){
|
async checkReady() {
|
||||||
await this.fetchTtsVoiceObjects()
|
await this.fetchTtsVoiceObjects()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,6 +81,10 @@ class SileroTtsProvider {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async refreshSession() {
|
||||||
|
await this.initSession()
|
||||||
|
}
|
||||||
|
|
||||||
//#################//
|
//#################//
|
||||||
// TTS Interfaces //
|
// TTS Interfaces //
|
||||||
//#################//
|
//#################//
|
||||||
@ -96,7 +102,7 @@ class SileroTtsProvider {
|
|||||||
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
|
||||||
}
|
}
|
||||||
@ -121,11 +127,12 @@ class SileroTtsProvider {
|
|||||||
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,
|
||||||
"speaker": voiceId
|
"speaker": voiceId,
|
||||||
|
"session": "sillytavern"
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -136,6 +143,31 @@ class SileroTtsProvider {
|
|||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Interface not used by Silero TTS
|
// Interface not used by Silero TTS
|
||||||
async fetchTtsFromHistory(history_item_id) {
|
async fetchTtsFromHistory(history_item_id) {
|
||||||
return Promise.resolve(history_item_id);
|
return Promise.resolve(history_item_id);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user