Make less obtrusive

This commit is contained in:
Cohee
2023-11-28 19:24:26 +02:00
parent a1098a4f31
commit 16527710b3

View File

@ -44,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}`
@ -64,7 +64,7 @@ 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() this.refreshSession()
await this.checkReady() await this.checkReady()
@ -73,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()
} }
@ -102,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
} }
@ -127,7 +127,7 @@ 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,
@ -144,26 +144,28 @@ class SileroTtsProvider {
} }
async initSession() { async initSession() {
console.info(`requesting new session`) console.info(`Silero TTS: requesting new session`);
const response = await doExtrasFetch( try {
`${this.settings.provider_endpoint}/session`, const response = await doExtrasFetch(
{ `${this.settings.provider_endpoint}/session`,
method: 'POST', {
headers: { method: 'POST',
'Content-Type': 'application/json', headers: {
'Cache-Control': 'no-cache' // Added this line to disable caching of file so new files are always played - Rolyat 7/7/23 'Content-Type': 'application/json',
}, 'Cache-Control': 'no-cache',
body: JSON.stringify({ },
"path": "sillytavern" body: JSON.stringify({
}) "path": "sillytavern",
} }),
) }
)
if (!response.ok && response.status !== 404) { if (!response.ok && response.status !== 404) {
toastr.error(response.statusText, 'Fetching Session Failed'); throw new Error(`HTTP ${response.status}: ${await response.text()}`);
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 // Interface not used by Silero TTS