Make less obtrusive

This commit is contained in:
Cohee 2023-11-28 19:24:26 +02:00
parent a1098a4f31
commit 16527710b3
1 changed files with 29 additions and 27 deletions

View File

@ -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