mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
lint: Require semicolons
This commit is contained in:
@@ -1,23 +1,23 @@
|
||||
import { getRequestHeaders, callPopup } from '../../../script.js'
|
||||
import { getPreviewString, saveTtsProviderSettings } from './index.js'
|
||||
import { initVoiceMap } from './index.js'
|
||||
import { getRequestHeaders, callPopup } from '../../../script.js';
|
||||
import { getPreviewString, saveTtsProviderSettings } from './index.js';
|
||||
import { initVoiceMap } from './index.js';
|
||||
|
||||
export { NovelTtsProvider }
|
||||
export { NovelTtsProvider };
|
||||
|
||||
class NovelTtsProvider {
|
||||
//########//
|
||||
// Config //
|
||||
//########//
|
||||
|
||||
settings
|
||||
voices = []
|
||||
separator = ' . '
|
||||
audioElement = document.createElement('audio')
|
||||
settings;
|
||||
voices = [];
|
||||
separator = ' . ';
|
||||
audioElement = document.createElement('audio');
|
||||
|
||||
defaultSettings = {
|
||||
voiceMap: {},
|
||||
customVoices: []
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Perform any text processing before passing to TTS engine.
|
||||
@@ -53,11 +53,11 @@ class NovelTtsProvider {
|
||||
|
||||
// Add a new Novel custom voice to provider
|
||||
async addCustomVoice(){
|
||||
const voiceName = await callPopup('<h3>Custom Voice name:</h3>', 'input')
|
||||
this.settings.customVoices.push(voiceName)
|
||||
this.populateCustomVoices()
|
||||
initVoiceMap() // Update TTS extension voiceMap
|
||||
saveTtsProviderSettings()
|
||||
const voiceName = await callPopup('<h3>Custom Voice name:</h3>', 'input');
|
||||
this.settings.customVoices.push(voiceName);
|
||||
this.populateCustomVoices();
|
||||
initVoiceMap(); // Update TTS extension voiceMap
|
||||
saveTtsProviderSettings();
|
||||
}
|
||||
|
||||
// Delete selected custom voice from provider
|
||||
@@ -68,52 +68,52 @@ class NovelTtsProvider {
|
||||
if (voiceIndex !== -1) {
|
||||
this.settings.customVoices.splice(voiceIndex, 1);
|
||||
}
|
||||
this.populateCustomVoices()
|
||||
initVoiceMap() // Update TTS extension voiceMap
|
||||
saveTtsProviderSettings()
|
||||
this.populateCustomVoices();
|
||||
initVoiceMap(); // Update TTS extension voiceMap
|
||||
saveTtsProviderSettings();
|
||||
}
|
||||
|
||||
// Create the UI dropdown list of voices in provider
|
||||
populateCustomVoices(){
|
||||
let voiceSelect = $('#tts-novel-custom-voices-select')
|
||||
voiceSelect.empty()
|
||||
let voiceSelect = $('#tts-novel-custom-voices-select');
|
||||
voiceSelect.empty();
|
||||
this.settings.customVoices.forEach(voice => {
|
||||
voiceSelect.append(`<option>${voice}</option>`)
|
||||
})
|
||||
voiceSelect.append(`<option>${voice}</option>`);
|
||||
});
|
||||
}
|
||||
|
||||
async loadSettings(settings) {
|
||||
// Populate Provider UI given input settings
|
||||
if (Object.keys(settings).length == 0) {
|
||||
console.info('Using default TTS Provider settings')
|
||||
console.info('Using default TTS Provider settings');
|
||||
}
|
||||
$('#tts-novel-custom-voices-add').on('click', () => (this.addCustomVoice()))
|
||||
$('#tts-novel-custom-voices-delete').on('click',() => (this.deleteCustomVoice()))
|
||||
$('#tts-novel-custom-voices-add').on('click', () => (this.addCustomVoice()));
|
||||
$('#tts-novel-custom-voices-delete').on('click',() => (this.deleteCustomVoice()));
|
||||
|
||||
// Only accept keys defined in defaultSettings
|
||||
this.settings = this.defaultSettings
|
||||
this.settings = this.defaultSettings;
|
||||
|
||||
for (const key in settings) {
|
||||
if (key in this.settings) {
|
||||
this.settings[key] = settings[key]
|
||||
this.settings[key] = settings[key];
|
||||
} else {
|
||||
throw `Invalid setting passed to TTS Provider: ${key}`
|
||||
throw `Invalid setting passed to TTS Provider: ${key}`;
|
||||
}
|
||||
}
|
||||
|
||||
this.populateCustomVoices()
|
||||
await this.checkReady()
|
||||
console.debug('NovelTTS: Settings loaded')
|
||||
this.populateCustomVoices();
|
||||
await this.checkReady();
|
||||
console.debug('NovelTTS: Settings loaded');
|
||||
}
|
||||
|
||||
// Perform a simple readiness check by trying to fetch voiceIds
|
||||
// Doesnt really do much for Novel, not seeing a good way to test this at the moment.
|
||||
async checkReady(){
|
||||
await this.fetchTtsVoiceObjects()
|
||||
await this.fetchTtsVoiceObjects();
|
||||
}
|
||||
|
||||
async onRefreshClick() {
|
||||
return
|
||||
return;
|
||||
}
|
||||
|
||||
//#################//
|
||||
@@ -122,15 +122,15 @@ class NovelTtsProvider {
|
||||
|
||||
async getVoice(voiceName) {
|
||||
if (!voiceName) {
|
||||
throw 'TTS Voice name not provided'
|
||||
throw 'TTS Voice name not provided';
|
||||
}
|
||||
|
||||
return { name: voiceName, voice_id: voiceName, lang: 'en-US', preview_url: false}
|
||||
return { name: voiceName, voice_id: voiceName, lang: 'en-US', preview_url: false};
|
||||
}
|
||||
|
||||
async generateTts(text, voiceId) {
|
||||
const response = await this.fetchTtsGeneration(text, voiceId)
|
||||
return response
|
||||
const response = await this.fetchTtsGeneration(text, voiceId);
|
||||
return response;
|
||||
}
|
||||
|
||||
//###########//
|
||||
@@ -156,8 +156,8 @@ class NovelTtsProvider {
|
||||
// Add in custom voices to the map
|
||||
let addVoices = this.settings.customVoices.map(voice =>
|
||||
({ name: voice, voice_id: voice, lang: 'en-US', preview_url: false })
|
||||
)
|
||||
voices = voices.concat(addVoices)
|
||||
);
|
||||
voices = voices.concat(addVoices);
|
||||
|
||||
return voices;
|
||||
}
|
||||
@@ -167,10 +167,10 @@ class NovelTtsProvider {
|
||||
this.audioElement.pause();
|
||||
this.audioElement.currentTime = 0;
|
||||
|
||||
const text = getPreviewString('en-US')
|
||||
const response = await this.fetchTtsGeneration(text, id)
|
||||
const text = getPreviewString('en-US');
|
||||
const response = await this.fetchTtsGeneration(text, id);
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP ${response.status}`)
|
||||
throw new Error(`HTTP ${response.status}`);
|
||||
}
|
||||
|
||||
const audio = await response.blob();
|
||||
@@ -180,7 +180,7 @@ class NovelTtsProvider {
|
||||
}
|
||||
|
||||
async fetchTtsGeneration(inputText, voiceId) {
|
||||
console.info(`Generating new TTS for voice_id ${voiceId}`)
|
||||
console.info(`Generating new TTS for voice_id ${voiceId}`);
|
||||
const response = await fetch('/api/novelai/generate-voice',
|
||||
{
|
||||
method: 'POST',
|
||||
@@ -190,11 +190,11 @@ class NovelTtsProvider {
|
||||
'voice': voiceId,
|
||||
})
|
||||
}
|
||||
)
|
||||
);
|
||||
if (!response.ok) {
|
||||
toastr.error(response.statusText, 'TTS Generation Failed');
|
||||
throw new Error(`HTTP ${response.status}: ${await response.text()}`);
|
||||
}
|
||||
return response
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user