| 1 | 1 | import { doExtrasFetch } from '../../extensions.js';
|
| 2 | 2 | import { debounce } from '../../utils.js';
|
| 3 | 3 | import { saveTtsProviderSettings } from './index.js';
|
| 4 | | -
|
| 4 | + |
| 5 | 5 | export { AllTalkTtsProvider };
|
| 6 | | -
|
| 6 | + |
| 7 | 7 | class AllTalkTtsProvider {
|
| 8 | 8 | //########//
|
| 9 | 9 | // Config //
|
| 10 | 10 | //########//
|
| 11 | | -
|
| 11 | + |
| 12 | 12 | settings = {};
|
| 13 | 13 | constructor() {
|
| 14 | 14 | // Initialize with default settings if they are not already set
|
| 15 | 15 | this.settings = {
|
| 16 | 16 | provider_endpoint: this.settings.provider_endpoint || 'http://localhost:7851',
|
| 17 | 17 | server_version: this.settings.server_version || 'v2',
|
| 18 | 18 | language: this.settings.language || 'en',
|
| 19 | 19 | voiceMap: this.settings.voiceMap || {},
|
| 20 | 20 | at_generation_method: this.settings.at_generation_method || 'standard_generation',
|
| 21 | 21 | narrator_enabled: this.settings.narrator_enabled || 'false',
|
| 22 | 22 | at_narrator_text_not_inside: this.settings.at_narrator_text_not_inside || 'narrator',
|
| 23 | 23 | narrator_voice_gen: this.settings.narrator_voice_gen || 'Please set a voice',
|
| 24 | 24 | rvc_character_voice: this.settings.rvc_character_voice || 'Disabled',
|
| 25 | 25 | rvc_character_pitch: this.settings.rvc_character_pitch || '0',
|
| 26 | 26 | rvc_narrator_voice: this.settings.rvc_narrator_voice || 'Disabled',
|
| 27 | 27 | rvc_narrator_pitch: this.settings.rvc_narrator_pitch || '0',
|
| 28 | 28 | finetuned_model: this.settings.finetuned_model || 'false',
|
| 29 | 29 | };
|
| 30 | 30 | // Separate property for dynamically updated settings from the server
|
| 31 | 31 | this.dynamicSettings = {
|
| 32 | 32 | modelsAvailable: [],
|
| 33 | 33 | currentModel: '',
|
| 34 | 34 | deepspeed_available: false,
|
| 35 | 35 | deepspeed_enabled: false,
|
| 36 | 36 | lowvram_capable: false,
|
| 37 | 37 | lowvram_enabled: false,
|
| 38 | 38 | };
|
| 39 | 39 | this.rvcVoices = []; // Initialize rvcVoices as an empty array
|
| 40 | 40 | }
|
| 41 | 41 | ready = false;
|
| 42 | 42 | voices = [];
|
| 43 | 43 | separator = '. ';
|
| 44 | 44 | audioElement = document.createElement('audio');
|
| 45 | | -
|
| 45 | + |
| 46 | 46 | languageLabels = {
|
| 47 | 47 | 'Arabic': 'ar',
|
| 48 | 48 | 'Brazilian Portuguese': 'pt',
|
| 49 | 49 | 'Chinese': 'zh-cn',
|
| 50 | 50 | 'Czech': 'cs',
|
| 51 | 51 | 'Dutch': 'nl',
|
| 52 | 52 | 'English': 'en',
|
| 53 | 53 | 'French': 'fr',
|
| 54 | 54 | 'German': 'de',
|
| 55 | 55 | 'Italian': 'it',
|
| 56 | 56 | 'Polish': 'pl',
|
| 57 | 57 | 'Russian': 'ru',
|
| 58 | 58 | 'Spanish': 'es',
|
| 59 | 59 | 'Turkish': 'tr',
|
| 60 | 60 | 'Japanese': 'ja',
|
| 61 | 61 | 'Korean': 'ko',
|
| 62 | 62 | 'Hungarian': 'hu',
|
| 63 | 63 | 'Hindi': 'hi',
|
| 64 | 64 | };
|
| 65 | | -
|
| 65 | + |
| 66 | 66 | get settingsHtml() {
|
| 67 | 67 | // HTML template literals can trigger ESLint quotes warnings when quotes are used in HTML attributes.
|
| 68 | 68 | // Disabling quotes rule for this one line as it's a false positive with HTML template literals.
|
| 69 | 69 | // eslint-disable-next-line quotes
|
| 70 | 70 | let html = `<div class="at-settings-separator">AllTalk V2 Settings</div>`;
|
| 71 | | -
|
| 71 | + |
| 72 | 72 | html += `<div class='at-settings-row'>
|
| 73 | 73 | <div class='at-settings-option'>
|
| 74 | 74 | <label for='at_generation_method'>AllTalk TTS Generation Method</label>
|
| 75 | 75 | <select id='at_generation_method'>
|
| 76 | 76 | <option value='standard_generation'>Standard Audio Generation (AT Narrator - Optional)</option>
|
| 77 | 77 | <option value='streaming_enabled'>Streaming Audio Generation (AT Narrator - Disabled)</option>
|
| 78 | 78 | </select>
|
| 79 | 79 | </div>
|
| 80 | 80 | </div>`;
|
| 81 | | -
|
| 81 | + |
| 82 | 82 | html += `<div class='at-settings-row'>
|
| 83 | 83 | <div class='at-settings-option'>
|
| 84 | 84 | <label for='at_narrator_enabled'>AT Narrator</label>
|
| 85 | 85 | <select id='at_narrator_enabled'>
|
| 86 | 86 | <option value='true'>Enabled</option>
|
| 87 | 87 | <option value='silent'>Enabled (Silenced)</option>
|
| 88 | 88 | <option value='false'>Disabled</option>
|
| 89 | 89 | </select>
|
| 90 | 90 | </div>
|
| 91 | | -
|
| 91 | + |
| 92 | 92 | <div class='at-settings-option'>
|
| 93 | 93 | <label for='at_narrator_text_not_inside'>Text Not Inside * or " is</label>
|
| 94 | 94 | <select id='at_narrator_text_not_inside'>
|
| 95 | 95 | <option value='character'>Character</option>
|
| 96 | 96 | <option value='narrator'>Narrator</option>
|
| 97 | 97 | <option value='silent'>Silent</option>
|
| 98 | 98 | </select>
|
| 99 | 99 | </div>
|
| 100 | 100 | </div>`;
|
| 101 | | -
|
| 101 | + |
| 102 | 102 | html += `<div class='at-settings-row'>
|
| 103 | 103 | <div class='at-settings-option'>
|
| 104 | 104 | <label for='narrator_voice'>Narrator Voice</label>
|
| 105 | 105 | <select id='narrator_voice'>`;
|
| 106 | 106 | if (this.voices) {
|
| 107 | 107 | for (let voice of this.voices) {
|
| 108 | 108 | html += `<option value='${voice.voice_id}'>${voice.name}</option>`;
|
| 109 | 109 | }
|
| 110 | 110 | }
|
| 111 | 111 | html += `</select>
|
| 112 | 112 | </div>
|
| 113 | 113 | <div class='at-settings-option'>
|
| 114 | 114 | <label for='language_options'>Language</label>
|
| 115 | 115 | <select id='language_options'>`;
|
| 116 | 116 | for (let language in this.languageLabels) {
|
| 117 | 117 | html += `<option value='${this.languageLabels[language]}' ${this.languageLabels[language] === this.settings?.language ? 'selected="selected"' : ''}>${language}</option>`;
|
| 118 | 118 | }
|
| 119 | 119 | html += `</select>
|
| 120 | 120 | </div>
|
| 121 | 121 | </div>`;
|
| 122 | | -
|
| 122 | + |
| 123 | 123 | html += `<div class='at-settings-row'>
|
| 124 | 124 | <div class='at-settings-option'>
|
| 125 | 125 | <label for='rvc_character_voice'>RVC Character</label>
|
| 126 | 126 | <select id='rvc_character_voice'>`;
|
| 127 | 127 | if (this.rvcVoices) {
|
| 128 | 128 | for (let rvccharvoice of this.rvcVoices) {
|
| 129 | 129 | html += `<option value='${rvccharvoice.voice_id}'>${rvccharvoice.name}</option>`;
|
| 130 | 130 | }
|
| 131 | 131 | }
|
| 132 | 132 | html += `</select>
|
| 133 | 133 | </div>
|
| 134 | 134 | <div class='at-settings-option'>
|
| 135 | 135 | <label for='rvc_narrator_voice'>RVC Narrator</label>
|
| 136 | 136 | <select id='rvc_narrator_voice'>`;
|
| 137 | 137 | if (this.rvcVoices) {
|
| 138 | 138 | for (let rvcnarrvoice of this.rvcVoices) {
|
| 139 | 139 | html += `<option value='${rvcnarrvoice.voice_id}'>${rvcnarrvoice.name}</option>`;
|
| 140 | 140 | }
|
| 141 | 141 | }
|
| 142 | 142 | html += `</select>
|
| 143 | 143 | </div>
|
| 144 | 144 | </div>`;
|
| 145 | | -
|
| 145 | + |
| 146 | 146 | html += `<div class='at-settings-row'>
|
| 147 | 147 | <div class='at-settings-option'>
|
| 148 | 148 | <label for='rvc_character_pitch'>RVC Character Pitch</label>
|
| 149 | 149 | <select id='rvc_character_pitch'>`;
|
| 150 | 150 | for (let i = -24; i <= 24; i++) {
|
| 151 | 151 | const selected = i === 0 ? 'selected="selected"' : '';
|
| 152 | 152 | html += `<option value='${i}' ${selected}>${i}</option>`;
|
| 153 | 153 | }
|
| 154 | 154 | html += `</select>
|
| 155 | 155 | </div>
|
| 156 | 156 | <div class='at-settings-option'>
|
| 157 | 157 | <label for='rvc_narrator_pitch'>RVC Narrator Pitch</label>
|
| 158 | 158 | <select id='rvc_narrator_pitch'>`;
|
| 159 | 159 | for (let i = -24; i <= 24; i++) {
|
| 160 | 160 | const selected = i === 0 ? 'selected="selected"' : '';
|
| 161 | 161 | html += `<option value='${i}' ${selected}>${i}</option>`;
|
| 162 | 162 | }
|
| 163 | 163 | html += `</select>
|
| 164 | 164 | </div>
|
| 165 | 165 | </div>`;
|
| 166 | | -
|
| 166 | + |
| 167 | 167 | html += `<div class='at-model-endpoint-row'>
|
| 168 | 168 | <div class='at-model-option'>
|
| 169 | 169 | <label for='switch_model'>Switch Model</label>
|
| 170 | 170 | <select id='switch_model'>
|
| 171 | 171 | <!-- Options will be dynamically populated -->
|
| 172 | 172 | </select>
|
| 173 | 173 | </div>
|
| 174 | | -
|
| 174 | + |
| 175 | 175 | <div class='at-endpoint-option'>
|
| 176 | 176 | <label for='at_server'>AllTalk Endpoint:</label>
|
| 177 | 177 | <input id='at_server' type='text' class='text_pole' maxlength='80' value='${this.settings.provider_endpoint}'/>
|
| 178 | 178 | </div>
|
| 179 | 179 | </div>`;
|
| 180 | | -
|
| 180 | + |
| 181 | 181 | html += `<div class='at-settings-row'>
|
| 182 | 182 | <div class='at-settings-option'>
|
| 183 | 183 | <label for='server_version'>AllTalk Server Version</label>
|
| 184 | 184 | <select id='server_version'>
|
| 185 | 185 | <option value='v1'>AllTalk V1</option>
|
| 186 | 186 | <option value='v2'>AllTalk V2</option>
|
| 187 | 187 | </select>
|
| 188 | 188 | </div>
|
| 189 | 189 | </div>`;
|
| 190 | | -
|
| 190 | + |
| 191 | 191 | html += `<div class='at-model-endpoint-row'>
|
| 192 | 192 | <div class='at-settings-option'>
|
| 193 | 193 | <label for='low_vram'>Low VRAM</label>
|
| 194 | 194 | <input id='low_vram' type='checkbox'/>
|
| 195 | 195 | </div>
|
| 196 | 196 | <div class='at-settings-option'>
|
| 197 | 197 | <label for='deepspeed'>DeepSpeed</label>
|
| 198 | 198 | <input id='deepspeed' type='checkbox'/>
|
| 199 | 199 | </div>
|
| 200 | 200 | <div class='at-settings-option status-option'>
|
| 201 | 201 | <span>Status: <span id='status_info'>Ready</span></span>
|
| 202 | 202 | </div>
|
| 203 | 203 | <div class='at-settings-option empty-option'>
|
| 204 | 204 | <!-- This div remains empty for spacing -->
|
| 205 | 205 | </div>
|
| 206 | 206 | </div>`;
|
| 207 | | -
|
| 207 | + |
| 208 | 208 | html += `<div class='at-website-row'>
|
| 209 | 209 | <div class='at-website-option'>
|
| 210 | 210 | <span>AllTalk V2<a target='_blank' href='${this.settings.provider_endpoint}'>Config & Docs</a>.</span>
|
| 211 | 211 | </div>
|
| 212 | | -
|
| 212 | + |
| 213 | 213 | <div class='at-website-option'>
|
| 214 | 214 | <span>AllTalk <a target='_blank' href='https://github.com/erew123/alltalk_tts/'>Website</a>.</span>
|
| 215 | 215 | </div>
|
| 216 | 216 | </div>`;
|
| 217 | | -
|
| 217 | + |
| 218 | 218 | html += `<div class='at-website-row'>
|
| 219 | 219 | <div class='at-website-option'>
|
| 220 | 220 | <span>- If you <strong>change your TTS engine</strong> in AllTalk, you will need to <strong>Reload</strong> (button above) and re-select your voices.</span><br><br>
|
| 221 | 221 | <span>- Assuming the server is <strong>Status: Ready</strong>, most problems will be resolved by hitting Reload and selecting voices that match the loaded TTS engine.</span><br><br>
|
| 222 | 222 | <span>- <strong>Text-generation-webui</strong> users - Uncheck <strong>Enable TTS</strong> in the TGWUI interface, or you will hear 2x voices and file names being generated.</span>
|
| 223 | 223 | </div>
|
| 224 | 224 | </div>`;
|
| 225 | | -
|
| 225 | + |
| 226 | 226 | return html;
|
| 227 | 227 | }
|
| 228 | | -
|
| 228 | + |
| 229 | | -
|
| 229 | + |
| 230 | 230 | //#################//
|
| 231 | 231 | // Startup ST & AT //
|
| 232 | 232 | //#################//
|
| 233 | | -
|
| 233 | + |
| 234 | 234 | async loadSettings(settings) {
|
| 235 | 235 | updateStatus('Offline');
|
| 236 | | -
|
| 236 | + |
| 237 | 237 | if (Object.keys(settings).length === 0) {
|
| 238 | 238 | console.info('Using default AllTalk TTS Provider settings');
|
| 239 | 239 | } else {
|
| 240 | 240 | // Populate settings with provided values, ignoring server-provided settings
|
| 241 | 241 | for (const key in settings) {
|
| 242 | 242 | if (key in this.settings) {
|
| 243 | 243 | this.settings[key] = settings[key];
|
| 244 | 244 | } else {
|
| 245 | 245 | console.debug(`Ignoring non-user-configurable setting: ${key}`);
|
| 246 | 246 | }
|
| 247 | 247 | }
|
| 248 | 248 | }
|
| 249 | | -
|
| 249 | + |
| 250 | 250 | // Update UI elements to reflect the loaded settings
|
| 251 | 251 | $('#at_server').val(this.settings.provider_endpoint);
|
| 252 | 252 | $('#language_options').val(this.settings.language);
|
| 253 | 253 | $('#at_generation_method').val(this.settings.at_generation_method);
|
| 254 | 254 | $('#at_narrator_enabled').val(this.settings.narrator_enabled);
|
| 255 | 255 | $('#at_narrator_text_not_inside').val(this.settings.at_narrator_text_not_inside);
|
| 256 | 256 | $('#narrator_voice').val(this.settings.narrator_voice_gen);
|
| 257 | 257 | $('#rvc_character_voice').val(this.settings.rvc_character_voice);
|
| 258 | 258 | $('#rvc_narrator_voice').val(this.settings.rvc_narrator_voice);
|
| 259 | 259 | $('#rvc_character_pitch').val(this.settings.rvc_character_pitch);
|
| 260 | 260 | $('#rvc_narrator_pitch').val(this.settings.rvc_narrator_pitch);
|
| 261 | | -
|
| 261 | + |
| 262 | 262 | console.debug('AllTalkTTS: Settings loaded');
|
| 263 | 263 | try {
|
| 264 | 264 | // Check if TTS provider is ready
|
| 265 | 265 | await this.checkReadysetupEventListeners();
|
| 266 | | - await this.updateSettingsFromServer(); // Fetch dynamic settings from the TTS server
|
| 266 | + this.updateLanguageDropdown(); |
| 267 | | - await this.fetchTtsVoiceObjects(); // Fetch voices only if service is ready
|
| 267 | + await this.checkReady(); |
| 268 | 268 | await this.fetchRvcVoiceObjectsupdateSettingsFromServer(); // Fetch RVCdynamic voices
settings from the TTS server |
| 269 | | - this.updateNarratorVoicesDropdown();
|
| 269 | + await this.fetchTtsVoiceObjects(); // Fetch voices only if service is ready |
| 270 | | - this.updateLanguageDropdown();
|
| 270 | + await this.fetchRvcVoiceObjects(); // Fetch RVC voices |
| 271 | 271 | this.setupEventListenersupdateNarratorVoicesDropdown();
|
| 272 | 272 | this.applySettingsToHTML();
|
| 273 | 273 | updateStatus('Ready');
|
| 274 | 274 | } catch (error) {
|
| 275 | 275 | console.error('Error loading settings:', error);
|
| 276 | 276 | updateStatus('Offline');
|
| 277 | 277 | }
|
| 278 | 278 | }
|
| 279 | | -
|
| 279 | + |
| 280 | | -
|
| 280 | + |
| 281 | 281 | applySettingsToHTML() {
|
| 282 | 282 | const narratorVoiceSelect = document.getElementById('narrator_voice');
|
| 283 | 283 | const atNarratorSelect = document.getElementById('at_narrator_enabled');
|
| 284 | 284 | const textNotInsideSelect = document.getElementById('at_narrator_text_not_inside');
|
| 285 | 285 | const generationMethodSelect = document.getElementById('at_generation_method');
|
| 286 | 286 | this.settings.narrator_voice = this.settings.narrator_voice_gen;
|
| 287 | 287 | // Apply settings to Narrator Voice dropdown
|
| 288 | 288 | if (narratorVoiceSelect && this.settings.narrator_voice) {
|
| 289 | 289 | narratorVoiceSelect.value = this.settings.narrator_voice; // Remove the parentheses
|
| 290 | 290 | }
|
| 291 | 291 | // Apply settings to AT Narrator Enabled dropdown
|
| 292 | 292 | if (atNarratorSelect) {
|
| 293 | 293 | const ttsPassAsterisksCheckbox = document.getElementById('tts_pass_asterisks');
|
| 294 | 294 | const ttsNarrateQuotedCheckbox = document.getElementById('tts_narrate_quoted');
|
| 295 | 295 | const ttsNarrateDialoguesCheckbox = document.getElementById('tts_narrate_dialogues');
|
| 296 | 296 | if (this.settings.narrator_enabled) {
|
| 297 | 297 | ttsPassAsterisksCheckbox.checked = false;
|
| 298 | 298 | $('#tts_pass_asterisks').click();
|
| 299 | 299 | $('#tts_pass_asterisks').trigger('change');
|
| 300 | 300 | }
|
| 301 | 301 | if (!this.settings.narrator_enabled) {
|
| 302 | 302 | ttsPassAsterisksCheckbox.checked = true;
|
| 303 | 303 | $('#tts_pass_asterisks').click();
|
| 304 | 304 | $('#tts_pass_asterisks').trigger('change');
|
| 305 | 305 | }
|
| 306 | 306 | if (this.settings.narrator_enabled) {
|
| 307 | 307 | ttsNarrateQuotedCheckbox.checked = true;
|
| 308 | 308 | ttsNarrateDialoguesCheckbox.checked = true;
|
| 309 | 309 | $('#tts_narrate_quoted').click();
|
| 310 | 310 | $('#tts_narrate_quoted').trigger('change');
|
| 311 | 311 | $('#tts_narrate_dialogues').click();
|
| 312 | 312 | $('#tts_narrate_dialogues').trigger('change');
|
| 313 | 313 | }
|
| 314 | 314 | atNarratorSelect.value = this.settings.narrator_enabled.toString();
|
| 315 | 315 | this.settings.narrator_enabled = this.settings.narrator_enabled.toString();
|
| 316 | 316 | }
|
| 317 | 317 | const languageSelect = document.getElementById('language_options');
|
| 318 | 318 | if (languageSelect && this.settings.language) {
|
| 319 | 319 | languageSelect.value = this.settings.language;
|
| 320 | 320 | }
|
| 321 | 321 | if (textNotInsideSelect && this.settings.text_not_inside) {
|
| 322 | 322 | textNotInsideSelect.value = this.settings.text_not_inside;
|
| 323 | 323 | this.settings.at_narrator_text_not_inside = this.settings.text_not_inside;
|
| 324 | 324 | }
|
| 325 | 325 | if (generationMethodSelect && this.settings.at_generation_method) {
|
| 326 | 326 | generationMethodSelect.value = this.settings.at_generation_method;
|
| 327 | 327 | }
|
| 328 | 328 | const isStreamingEnabled = this.settings.at_generation_method === 'streaming_enabled';
|
| 329 | 329 | if (isStreamingEnabled) {
|
| 330 | 330 | if (atNarratorSelect) atNarratorSelect.disabled = true;
|
| 331 | 331 | if (textNotInsideSelect) textNotInsideSelect.disabled = true;
|
| 332 | 332 | if (narratorVoiceSelect) narratorVoiceSelect.disabled = true;
|
| 333 | 333 | } else {
|
| 334 | 334 | if (atNarratorSelect) atNarratorSelect.disabled = false;
|
| 335 | 335 | if (textNotInsideSelect) textNotInsideSelect.disabled = !this.settings.narrator_enabled;
|
| 336 | 336 | if (narratorVoiceSelect) narratorVoiceSelect.disabled = !this.settings.narrator_enabled;
|
| 337 | 337 | }
|
| 338 | 338 | }
|
| 339 | | -
|
| 339 | + |
| 340 | | -
|
| 340 | + |
| 341 | 341 | //##############################//
|
| 342 | 342 | // Check AT Server is Available //
|
| 343 | 343 | //##############################//
|
| 344 | | -
|
| 344 | + |
| 345 | 345 | async checkReady() {
|
| 346 | 346 | try {
|
| 347 | 347 | const response = await fetch(`${this.settings.provider_endpoint}/api/ready`);
|
| 348 | 348 | // Check if the HTTP request was successful
|
| 349 | 349 | if (!response.ok) {
|
| 350 | 350 | throw new Error(`HTTP Error Response: ${response.status} ${response.statusText}`);
|
| 351 | 351 | }
|
| 352 | 352 | const statusText = await response.text();
|
| 353 | 353 | // Check if the response is 'Ready'
|
| 354 | 354 | if (statusText === 'Ready') {
|
| 355 | 355 | this.ready = true; // Set the ready flag to true
|
| 356 | 356 | console.log('TTS service is ready.');
|
| 357 | 357 | } else {
|
| 358 | 358 | this.ready = false;
|
| 359 | 359 | console.log('TTS service is not ready.');
|
| 360 | 360 | }
|
| 361 | 361 | } catch (error) {
|
| 362 | 362 | console.error('Error checking TTS service readiness:', error);
|
| 363 | 363 | this.ready = false; // Ensure ready flag is set to false in case of error
|
| 364 | 364 | }
|
| 365 | 365 | }
|
| 366 | | -
|
| 366 | + |
| 367 | 367 | //######################//
|
| 368 | 368 | // Get Available Voices //
|
| 369 | 369 | //######################//
|
| 370 | | -
|
| 370 | + |
| 371 | 371 | async fetchTtsVoiceObjects() {
|
| 372 | 372 | const response = await fetch(`${this.settings.provider_endpoint}/api/voices`);
|
| 373 | 373 | if (!response.ok) {
|
| 374 | 374 | const errorText = await response.text();
|
| 375 | 375 | throw new Error(`HTTP ${response.status}: ${errorText}`);
|
| 376 | 376 | }
|
| 377 | 377 | const data = await response.json();
|
| 378 | 378 | const voices = data.voices.map(filename => {
|
| 379 | 379 | return {
|
| 380 | 380 | name: filename,
|
| 381 | 381 | voice_id: filename,
|
| 382 | 382 | preview_url: null, // Preview URL will be dynamically generated
|
| 383 | 383 | lang: 'en', // Default language
|
| 384 | 384 | };
|
| 385 | 385 | });
|
| 386 | 386 | this.voices = voices; // Assign to the class property
|
| 387 | 387 | return voices; // Also return this list
|
| 388 | 388 | }
|
| 389 | | -
|
| 389 | + |
| 390 | 390 | async fetchRvcVoiceObjects() {
|
| 391 | 391 | if (this.settings.server_version !== 'v2') {
|
| 392 | 392 | console.log('Skipping RVC voices fetch for V1 server');
|
| 393 | 393 | return [];
|
| 394 | 394 | }
|
| 395 | | -
|
| 395 | + |
| 396 | 396 | console.log('Fetching RVC Voices');
|
| 397 | 397 | try {
|
| 398 | 398 | const response = await fetch(`${this.settings.provider_endpoint}/api/rvcvoices`);
|
| 399 | 399 | if (!response.ok) {
|
| 400 | 400 | const errorText = await response.text();
|
| 401 | 401 | console.error('Error text:', errorText);
|
| 402 | 402 | throw new Error(`HTTP ${response.status}: ${errorText}`);
|
| 403 | 403 | }
|
| 404 | | -
|
| 404 | + |
| 405 | 405 | const data = await response.json();
|
| 406 | 406 | if (!data || !data.rvcvoices) {
|
| 407 | 407 | console.error('Invalid data format:', data);
|
| 408 | 408 | throw new Error('Invalid data format received from /api/rvcvoices');
|
| 409 | 409 | }
|
| 410 | | -
|
| 410 | + |
| 411 | 411 | const voices = data.rvcvoices.map(filename => {
|
| 412 | 412 | return {
|
| 413 | 413 | name: filename,
|
| 414 | 414 | voice_id: filename,
|
| 415 | 415 | };
|
| 416 | 416 | });
|
| 417 | | -
|
| 417 | + |
| 418 | 418 | console.log('RVC voices:', voices);
|
| 419 | 419 | this.rvcVoices = voices; // Assign to the class property
|
| 420 | 420 | this.updateRvcVoiceDropdowns(); // Update UI after fetching voices
|
| 421 | 421 | return voices; // Also return this list
|
| 422 | 422 | } catch (error) {
|
| 423 | 423 | console.error('Error fetching RVC voices:', error);
|
| 424 | 424 | this.rvcVoices = [{ name: 'Disabled', voice_id: 'Disabled' }]; // Set default on error
|
| 425 | 425 | throw error;
|
| 426 | 426 | } finally {
|
| 427 | 427 | // Ensure dropdowns are updated even if there was an error
|
| 428 | 428 | this.updateRvcVoiceDropdowns();
|
| 429 | 429 | }
|
| 430 | 430 | }
|
| 431 | | -
|
| 431 | + |
| 432 | 432 | //##########################################//
|
| 433 | 433 | // Get Current AT Server Config & Update ST //
|
| 434 | 434 | //##########################################//
|
| 435 | | -
|
| 435 | + |
| 436 | 436 | async updateSettingsFromServer() {
|
| 437 | 437 | try {
|
| 438 | 438 | const response = await fetch(`${this.settings.provider_endpoint}/api/currentsettings`);
|
| 439 | 439 | if (!response.ok) {
|
| 440 | 440 | throw new Error(`Failed to fetch current settings: ${response.statusText}`);
|
| 441 | 441 | }
|
| 442 | 442 | const currentSettings = await response.json();
|
| 443 | 443 | currentSettings.models_available.sort((a, b) => a.name.localeCompare(b.name));
|
| 444 | | -
|
| 444 | + |
| 445 | 445 | this.settings.enginesAvailable = currentSettings.engines_available;
|
| 446 | 446 | this.settings.currentEngineLoaded = currentSettings.current_engine_loaded;
|
| 447 | 447 | this.settings.modelsAvailable = currentSettings.models_available;
|
| 448 | 448 | this.settings.currentModel = currentSettings.current_model_loaded;
|
| 449 | 449 | this.settings.deepspeed_capable = currentSettings.deepspeed_capable;
|
| 450 | 450 | this.settings.deepspeed_available = currentSettings.deepspeed_available;
|
| 451 | 451 | this.settings.deepspeed_enabled = currentSettings.deepspeed_enabled;
|
| 452 | 452 | this.settings.lowvram_capable = currentSettings.lowvram_capable;
|
| 453 | 453 | this.settings.lowvram_enabled = currentSettings.lowvram_enabled;
|
| 454 | | -
|
| 454 | + |
| 455 | 455 | await this.fetchRvcVoiceObjects(); // Fetch RVC voices
|
| 456 | | -
|
| 456 | + |
| 457 | 457 | this.updateModelDropdown();
|
| 458 | 458 | this.updateCheckboxes();
|
| 459 | 459 | this.updateRvcVoiceDropdowns(); // Update the RVC voice dropdowns
|
| 460 | 460 | } catch (error) {
|
| 461 | 461 | console.error(`Error updating settings from server: ${error}`);
|
| 462 | 462 | }
|
| 463 | 463 | }
|
| 464 | | -
|
| 464 | + |
| 465 | 465 | updateRvcVoiceDropdowns() {
|
| 466 | 466 | // Handle all RVC-related elements
|
| 467 | 467 | const rvcElements = document.querySelectorAll('.rvc-setting');
|
| 468 | 468 | const isV2 = this.settings.server_version === 'v2';
|
| 469 | | -
|
| 469 | + |
| 470 | 470 | rvcElements.forEach(element => {
|
| 471 | 471 | element.style.display = isV2 ? 'block' : 'none';
|
| 472 | 472 | });
|
| 473 | | -
|
| 473 | + |
| 474 | 474 | // Update and disable/enable character voice dropdown
|
| 475 | 475 | const rvcCharacterVoiceSelect = document.getElementById('rvc_character_voice');
|
| 476 | 476 | if (rvcCharacterVoiceSelect) {
|
| 477 | 477 | rvcCharacterVoiceSelect.disabled = !isV2;
|
| 478 | 478 | if (this.rvcVoices) {
|
| 479 | 479 | rvcCharacterVoiceSelect.innerHTML = '';
|
| 480 | 480 | for (let voice of this.rvcVoices) {
|
| 481 | 481 | const option = document.createElement('option');
|
| 482 | 482 | option.value = voice.voice_id;
|
| 483 | 483 | option.textContent = voice.name;
|
| 484 | 484 | if (voice.voice_id === this.settings.rvc_character_voice) {
|
| 485 | 485 | option.selected = true;
|
| 486 | 486 | }
|
| 487 | 487 | rvcCharacterVoiceSelect.appendChild(option);
|
| 488 | 488 | }
|
| 489 | 489 | }
|
| 490 | 490 | }
|
| 491 | | -
|
| 491 | + |
| 492 | 492 | // Update and disable/enable narrator voice dropdown
|
| 493 | 493 | const rvcNarratorVoiceSelect = document.getElementById('rvc_narrator_voice');
|
| 494 | 494 | if (rvcNarratorVoiceSelect) {
|
| 495 | 495 | rvcNarratorVoiceSelect.disabled = !isV2;
|
| 496 | 496 | if (this.rvcVoices) {
|
| 497 | 497 | rvcNarratorVoiceSelect.innerHTML = '';
|
| 498 | 498 | for (let voice of this.rvcVoices) {
|
| 499 | 499 | const option = document.createElement('option');
|
| 500 | 500 | option.value = voice.voice_id;
|
| 501 | 501 | option.textContent = voice.name;
|
| 502 | 502 | if (voice.voice_id === this.settings.rvc_narrator_voice) {
|
| 503 | 503 | option.selected = true;
|
| 504 | 504 | }
|
| 505 | 505 | rvcNarratorVoiceSelect.appendChild(option);
|
| 506 | 506 | }
|
| 507 | 507 | }
|
| 508 | 508 | }
|
| 509 | | -
|
| 509 | + |
| 510 | 510 | // Update pitch inputs
|
| 511 | 511 | const characterPitch = document.getElementById('rvc_character_pitch');
|
| 512 | 512 | if (characterPitch) {
|
| 513 | 513 | characterPitch.disabled = !isV2;
|
| 514 | 514 | }
|
| 515 | | -
|
| 515 | + |
| 516 | 516 | const narratorPitch = document.getElementById('rvc_narrator_pitch');
|
| 517 | 517 | if (narratorPitch) {
|
| 518 | 518 | narratorPitch.disabled = !isV2;
|
| 519 | 519 | }
|
| 520 | 520 | }
|
| 521 | | -
|
| 521 | + |
| 522 | 522 | //###################################################//
|
| 523 | 523 | // Get Current AT Server Config & Update ST (Models) //
|
| 524 | 524 | //###################################################//
|
| 525 | | -
|
| 525 | + |
| 526 | 526 | updateModelDropdown() {
|
| 527 | 527 | const modelSelect = document.getElementById('switch_model');
|
| 528 | 528 | if (modelSelect) {
|
| 529 | 529 | modelSelect.innerHTML = ''; // Clear existing options
|
| 530 | 530 | this.settings.modelsAvailable.forEach(model => {
|
| 531 | 531 | const option = document.createElement('option');
|
| 532 | 532 | option.value = model.name;
|
| 533 | 533 | option.textContent = model.name; // Use model name directly
|
| 534 | 534 | option.selected = model.name === this.settings.currentModel;
|
| 535 | 535 | modelSelect.appendChild(option);
|
| 536 | 536 | });
|
| 537 | 537 | }
|
| 538 | 538 | }
|
| 539 | | -
|
| 539 | + |
| 540 | 540 | //#######################################################//
|
| 541 | 541 | // Get Current AT Server Config & Update ST (DS and LVR) //
|
| 542 | 542 | //#######################################################//
|
| 543 | | -
|
| 543 | + |
| 544 | 544 | updateCheckboxes() {
|
| 545 | 545 | const deepspeedCheckbox = document.getElementById('deepspeed');
|
| 546 | 546 | const lowVramCheckbox = document.getElementById('low_vram');
|
| 547 | | -
|
| 547 | + |
| 548 | 548 | // Handle DeepSpeed checkbox
|
| 549 | 549 | if (deepspeedCheckbox) {
|
| 550 | 550 | if (this.settings.deepspeed_capable) {
|
| 551 | 551 | // If TTS engine is capable of using DeepSpeed
|
| 552 | 552 | deepspeedCheckbox.disabled = !this.settings.deepspeed_available;
|
| 553 | 553 | this.settings.deepspeed_enabled = this.settings.deepspeed_available && this.settings.deepspeed_enabled;
|
| 554 | 554 | } else {
|
| 555 | 555 | // If TTS engine is NOT capable of using DeepSpeed
|
| 556 | 556 | deepspeedCheckbox.disabled = true;
|
| 557 | 557 | this.settings.deepspeed_enabled = false;
|
| 558 | 558 | }
|
| 559 | 559 | deepspeedCheckbox.checked = this.settings.deepspeed_enabled;
|
| 560 | 560 | }
|
| 561 | | -
|
| 561 | + |
| 562 | 562 | // Handle Low VRAM checkbox
|
| 563 | 563 | if (lowVramCheckbox) {
|
| 564 | 564 | if (this.settings.lowvram_capable) {
|
| 565 | 565 | // If TTS engine is capable of low VRAM
|
| 566 | 566 | lowVramCheckbox.disabled = false;
|
| 567 | 567 | } else {
|
| 568 | 568 | // If TTS engine is NOT capable of low VRAM
|
| 569 | 569 | lowVramCheckbox.disabled = true;
|
| 570 | 570 | this.settings.lowvram_enabled = false;
|
| 571 | 571 | }
|
| 572 | 572 | lowVramCheckbox.checked = this.settings.lowvram_enabled;
|
| 573 | 573 | }
|
| 574 | 574 | }
|
| 575 | | -
|
| 575 | + |
| 576 | | -
|
| 576 | + |
| 577 | 577 | //###############################################################//
|
| 578 | 578 | // Get Current AT Server Config & Update ST (AT Narrator Voices) //
|
| 579 | 579 | //###############################################################//
|
| 580 | | -
|
| 580 | + |
| 581 | 581 | updateNarratorVoicesDropdown() {
|
| 582 | 582 | const narratorVoiceSelect = document.getElementById('narrator_voice');
|
| 583 | 583 | if (narratorVoiceSelect && this.voices) {
|
| 584 | 584 | // Clear existing options
|
| 585 | 585 | narratorVoiceSelect.innerHTML = '';
|
| 586 | 586 | // Add new options
|
| 587 | 587 | for (let voice of this.voices) {
|
| 588 | 588 | const option = document.createElement('option');
|
| 589 | 589 | option.value = voice.voice_id;
|
| 590 | 590 | option.textContent = voice.name;
|
| 591 | 591 | narratorVoiceSelect.appendChild(option);
|
| 592 | 592 | }
|
| 593 | 593 | }
|
| 594 | 594 | }
|
| 595 | | -
|
| 595 | + |
| 596 | 596 | //######################################################//
|
| 597 | 597 | // Get Current AT Server Config & Update ST (Languages) //
|
| 598 | 598 | //######################################################//
|
| 599 | | -
|
| 599 | + |
| 600 | 600 | updateLanguageDropdown() {
|
| 601 | 601 | const languageSelect = document.getElementById('language_options');
|
| 602 | 602 | if (languageSelect) {
|
| 603 | 603 | // Ensure default language is set
|
| 604 | 604 | this.settings.language = this.settings.language || 'en';
|
| 605 | | -
|
| 605 | + |
| 606 | 606 | languageSelect.innerHTML = '';
|
| 607 | 607 | for (let language in this.languageLabels) {
|
| 608 | 608 | const option = document.createElement('option');
|
| 609 | 609 | option.value = this.languageLabels[language];
|
| 610 | 610 | option.textContent = language;
|
| 611 | 611 | if (this.languageLabels[language] === this.settings.language) {
|
| 612 | 612 | option.selected = true;
|
| 613 | 613 | }
|
| 614 | 614 | languageSelect.appendChild(option);
|
| 615 | 615 | }
|
| 616 | 616 | }
|
| 617 | 617 | }
|
| 618 | | -
|
| 618 | + |
| 619 | 619 | //########################################//
|
| 620 | 620 | // Start AT TTS extenstion page listeners //
|
| 621 | 621 | //########################################//
|
| 622 | | -
|
| 622 | + |
| 623 | 623 | setupEventListeners() {
|
| 624 | 624 | // Define the event handler function
|
| 625 | 625 | const onModelSelectChange = async (event) => {
|
| 626 | 626 | console.log('Model select change event triggered');
|
| 627 | 627 | const selectedModel = event.target.value;
|
| 628 | 628 | console.log(`Selected model: ${selectedModel}`);
|
| 629 | 629 | updateStatus('Processing');
|
| 630 | 630 | try {
|
| 631 | 631 | const response = await fetch(`${this.settings.provider_endpoint}/api/reload?tts_method=${encodeURIComponent(selectedModel)}`, {
|
| 632 | 632 | method: 'POST',
|
| 633 | 633 | });
|
| 634 | 634 | if (!response.ok) {
|
| 635 | 635 | throw new Error(`HTTP Error: ${response.status}`);
|
| 636 | 636 | }
|
| 637 | 637 | const data = await response.json();
|
| 638 | 638 | console.log('POST response data:', data);
|
| 639 | 639 | updateStatus('Ready');
|
| 640 | 640 | } catch (error) {
|
| 641 | 641 | console.error('POST request error:', error);
|
| 642 | 642 | updateStatus('Error');
|
| 643 | 643 | }
|
| 644 | 644 | };
|
| 645 | | -
|
| 645 | + |
| 646 | 646 | // Switch Model Listener with debounce
|
| 647 | 647 | const modelSelect = document.getElementById('switch_model');
|
| 648 | 648 | if (modelSelect) {
|
| 649 | 649 | const debouncedModelSelectChange = debounce(onModelSelectChange, 1400);
|
| 650 | 650 | modelSelect.addEventListener('change', debouncedModelSelectChange);
|
| 651 | 651 | }
|
| 652 | | -
|
| 652 | + |
| 653 | 653 | // AllTalk Server version change listener
|
| 654 | 654 | const serverVersionSelect = document.getElementById('server_version');
|
| 655 | 655 | if (serverVersionSelect) {
|
| 656 | 656 | serverVersionSelect.addEventListener('change', async (event) => {
|
| 657 | 657 | this.settings.server_version = event.target.value;
|
| 658 | 658 | if (event.target.value === 'v2') {
|
| 659 | 659 | await this.fetchRvcVoiceObjects();
|
| 660 | 660 | }
|
| 661 | 661 | this.updateRvcVoiceDropdowns();
|
| 662 | 662 | this.onSettingsChange();
|
| 663 | 663 | });
|
| 664 | 664 | }
|
| 665 | | -
|
| 665 | + |
| 666 | 666 | // RVC Voice and Pitch listeners
|
| 667 | 667 | const rvcCharacterVoiceSelect = document.getElementById('rvc_character_voice');
|
| 668 | 668 | if (rvcCharacterVoiceSelect) {
|
| 669 | 669 | rvcCharacterVoiceSelect.addEventListener('change', (event) => {
|
| 670 | 670 | this.settings.rvccharacter_voice_gen = event.target.value;
|
| 671 | 671 | this.onSettingsChange();
|
| 672 | 672 | });
|
| 673 | 673 | }
|
| 674 | | -
|
| 674 | + |
| 675 | 675 | const rvcNarratorVoiceSelect = document.getElementById('rvc_narrator_voice');
|
| 676 | 676 | if (rvcNarratorVoiceSelect) {
|
| 677 | 677 | rvcNarratorVoiceSelect.addEventListener('change', (event) => {
|
| 678 | 678 | this.settings.rvcnarrator_voice_gen = event.target.value;
|
| 679 | 679 | this.onSettingsChange();
|
| 680 | 680 | });
|
| 681 | 681 | }
|
| 682 | | -
|
| 682 | + |
| 683 | 683 | const rvcCharacterPitchSelect = document.getElementById('rvc_character_pitch');
|
| 684 | 684 | if (rvcCharacterPitchSelect) {
|
| 685 | 685 | rvcCharacterPitchSelect.addEventListener('change', (event) => {
|
| 686 | 686 | this.settings.rvc_character_pitch = event.target.value;
|
| 687 | 687 | this.onSettingsChange();
|
| 688 | 688 | });
|
| 689 | 689 | }
|
| 690 | | -
|
| 690 | + |
| 691 | 691 | const rvcNarratorPitchSelect = document.getElementById('rvc_narrator_pitch');
|
| 692 | 692 | if (rvcNarratorPitchSelect) {
|
| 693 | 693 | rvcNarratorPitchSelect.addEventListener('change', (event) => {
|
| 694 | 694 | this.settings.rvc_narrator_pitch = event.target.value;
|
| 695 | 695 | this.onSettingsChange();
|
| 696 | 696 | });
|
| 697 | 697 | }
|
| 698 | | -
|
| 698 | + |
| 699 | 699 | // DeepSpeed Listener
|
| 700 | 700 | const deepspeedCheckbox = document.getElementById('deepspeed');
|
| 701 | 701 | if (deepspeedCheckbox) {
|
| 702 | 702 | const handleDeepSpeedChange = async (event) => {
|
| 703 | 703 | const deepSpeedValue = event.target.checked ? 'True' : 'False';
|
| 704 | 704 | updateStatus('Processing');
|
| 705 | 705 | try {
|
| 706 | 706 | const response = await fetch(`${this.settings.provider_endpoint}/api/deepspeed?new_deepspeed_value=${deepSpeedValue}`, {
|
| 707 | 707 | method: 'POST',
|
| 708 | 708 | });
|
| 709 | 709 | if (!response.ok) {
|
| 710 | 710 | throw new Error(`HTTP Error: ${response.status}`);
|
| 711 | 711 | }
|
| 712 | 712 | const data = await response.json();
|
| 713 | 713 | console.log('POST response data:', data);
|
| 714 | 714 | updateStatus('Ready');
|
| 715 | 715 | } catch (error) {
|
| 716 | 716 | console.error('POST request error:', error);
|
| 717 | 717 | updateStatus('Error');
|
| 718 | 718 | }
|
| 719 | 719 | };
|
| 720 | | -
|
| 720 | + |
| 721 | 721 | const debouncedHandleDeepSpeedChange = debounce(handleDeepSpeedChange, 300);
|
| 722 | 722 | deepspeedCheckbox.addEventListener('change', debouncedHandleDeepSpeedChange);
|
| 723 | 723 | }
|
| 724 | | -
|
| 724 | + |
| 725 | 725 | // Low VRAM Listener
|
| 726 | 726 | const lowVramCheckbox = document.getElementById('low_vram');
|
| 727 | 727 | if (lowVramCheckbox) {
|
| 728 | 728 | const handleLowVramChange = async (event) => {
|
| 729 | 729 | const lowVramValue = event.target.checked ? 'True' : 'False';
|
| 730 | 730 | updateStatus('Processing');
|
| 731 | 731 | try {
|
| 732 | 732 | const response = await fetch(`${this.settings.provider_endpoint}/api/lowvramsetting?new_low_vram_value=${lowVramValue}`, {
|
| 733 | 733 | method: 'POST',
|
| 734 | 734 | });
|
| 735 | 735 | if (!response.ok) {
|
| 736 | 736 | throw new Error(`HTTP Error: ${response.status}`);
|
| 737 | 737 | }
|
| 738 | 738 | const data = await response.json();
|
| 739 | 739 | console.log('POST response data:', data);
|
| 740 | 740 | updateStatus('Ready');
|
| 741 | 741 | } catch (error) {
|
| 742 | 742 | console.error('POST request error:', error);
|
| 743 | 743 | updateStatus('Error');
|
| 744 | 744 | }
|
| 745 | 745 | };
|
| 746 | | -
|
| 746 | + |
| 747 | 747 | const debouncedHandleLowVramChange = debounce(handleLowVramChange, 300);
|
| 748 | 748 | lowVramCheckbox.addEventListener('change', debouncedHandleLowVramChange);
|
| 749 | 749 | }
|
| 750 | | -
|
| 750 | + |
| 751 | 751 | // Other listeners without debounce since they don't need it
|
| 752 | 752 | const narratorVoiceSelect = document.getElementById('narrator_voice');
|
| 753 | 753 | if (narratorVoiceSelect) {
|
| 754 | 754 | narratorVoiceSelect.addEventListener('change', (event) => {
|
| 755 | 755 | this.settings.narrator_voice_gen = `${event.target.value}`;
|
| 756 | 756 | this.onSettingsChange();
|
| 757 | 757 | });
|
| 758 | 758 | }
|
| 759 | | -
|
| 759 | + |
| 760 | 760 | const textNotInsideSelect = document.getElementById('at_narrator_text_not_inside');
|
| 761 | 761 | if (textNotInsideSelect) {
|
| 762 | 762 | textNotInsideSelect.addEventListener('change', (event) => {
|
| 763 | 763 | this.settings.text_not_inside = event.target.value;
|
| 764 | 764 | this.onSettingsChange();
|
| 765 | 765 | });
|
| 766 | 766 | }
|
| 767 | | -
|
| 767 | + |
| 768 | 768 | // AT Narrator Dropdown Listener
|
| 769 | 769 | const atNarratorSelect = document.getElementById('at_narrator_enabled');
|
| 770 | 770 | const ttsPassAsterisksCheckbox = document.getElementById('tts_pass_asterisks');
|
| 771 | 771 | const ttsNarrateQuotedCheckbox = document.getElementById('tts_narrate_quoted');
|
| 772 | 772 | const ttsNarrateDialoguesCheckbox = document.getElementById('tts_narrate_dialogues');
|
| 773 | | -
|
| 773 | + |
| 774 | 774 | if (atNarratorSelect && textNotInsideSelect && narratorVoiceSelect) {
|
| 775 | 775 | atNarratorSelect.addEventListener('change', (event) => {
|
| 776 | 776 | const narratorOption = event.target.value;
|
| 777 | 777 | this.settings.narrator_enabled = narratorOption;
|
| 778 | | -
|
| 778 | + |
| 779 | 779 | const isNarratorDisabled = narratorOption === 'false';
|
| 780 | 780 | textNotInsideSelect.disabled = isNarratorDisabled;
|
| 781 | 781 | narratorVoiceSelect.disabled = isNarratorDisabled;
|
| 782 | | -
|
| 782 | + |
| 783 | 783 | if (narratorOption === 'true') {
|
| 784 | 784 | ttsPassAsterisksCheckbox.checked = false;
|
| 785 | 785 | $('#tts_pass_asterisks').click();
|
| 786 | 786 | $('#tts_pass_asterisks').trigger('change');
|
| 787 | 787 | ttsNarrateQuotedCheckbox.checked = true;
|
| 788 | 788 | ttsNarrateDialoguesCheckbox.checked = true;
|
| 789 | 789 | $('#tts_narrate_quoted').click();
|
| 790 | 790 | $('#tts_narrate_quoted').trigger('change');
|
| 791 | 791 | $('#tts_narrate_dialogues').click();
|
| 792 | 792 | $('#tts_narrate_dialogues').trigger('change');
|
| 793 | 793 | } else if (narratorOption === 'silent') {
|
| 794 | 794 | ttsPassAsterisksCheckbox.checked = false;
|
| 795 | 795 | $('#tts_pass_asterisks').click();
|
| 796 | 796 | $('#tts_pass_asterisks').trigger('change');
|
| 797 | 797 | } else {
|
| 798 | 798 | ttsPassAsterisksCheckbox.checked = true;
|
| 799 | 799 | $('#tts_pass_asterisks').click();
|
| 800 | 800 | $('#tts_pass_asterisks').trigger('change');
|
| 801 | 801 | }
|
| 802 | | -
|
| 802 | + |
| 803 | 803 | this.onSettingsChange();
|
| 804 | 804 | });
|
| 805 | 805 | }
|
| 806 | | -
|
| 806 | + |
| 807 | 807 | // Event Listener for AT Generation Method Dropdown
|
| 808 | 808 | const atGenerationMethodSelect = document.getElementById('at_generation_method');
|
| 809 | 809 | if (atGenerationMethodSelect) {
|
| 810 | 810 | atGenerationMethodSelect.addEventListener('change', (event) => {
|
| 811 | 811 | const selectedMethod = event.target.value;
|
| 812 | | -
|
| 812 | + |
| 813 | 813 | if (selectedMethod === 'streaming_enabled') {
|
| 814 | 814 | // Disable and unselect AT Narrator
|
| 815 | 815 | atNarratorSelect.disabled = true;
|
| 816 | 816 | atNarratorSelect.value = 'false';
|
| 817 | 817 | textNotInsideSelect.disabled = true;
|
| 818 | 818 | narratorVoiceSelect.disabled = true;
|
| 819 | 819 | } else if (selectedMethod === 'standard_generation') {
|
| 820 | 820 | // Enable AT Narrator
|
| 821 | 821 | atNarratorSelect.disabled = false;
|
| 822 | 822 | }
|
| 823 | 823 | this.settings.at_generation_method = selectedMethod;
|
| 824 | 824 | this.onSettingsChange();
|
| 825 | 825 | });
|
| 826 | 826 | }
|
| 827 | | -
|
| 827 | + |
| 828 | 828 | // Language Dropdown Listener
|
| 829 | 829 | const languageSelect = document.getElementById('language_options');
|
| 830 | 830 | if (languageSelect) {
|
| 831 | 831 | languageSelect.addEventListener('change', (event) => {
|
| 832 | 832 | this.settings.language = event.target.value;
|
| 833 | 833 | this.onSettingsChange();
|
| 834 | 834 | });
|
| 835 | 835 | }
|
| 836 | | -
|
| 836 | + |
| 837 | 837 | // AllTalk Endpoint Input Listener
|
| 838 | 838 | const atServerInput = document.getElementById('at_server');
|
| 839 | 839 | if (atServerInput) {
|
| 840 | 840 | atServerInput.addEventListener('input', (event) => {
|
| 841 | 841 | this.settings.provider_endpoint = event.target.value;
|
| 842 | 842 | this.onSettingsChange();
|
| 843 | 843 | });
|
| 844 | 844 | }
|
| 845 | 845 | }
|
| 846 | | -
|
| 846 | + |
| 847 | 847 | //#############################//
|
| 848 | 848 | // Store ST interface settings //
|
| 849 | 849 | //#############################//
|
| 850 | | -
|
| 850 | + |
| 851 | 851 | onSettingsChange() {
|
| 852 | 852 | // Update settings based on the UI elements
|
| 853 | 853 | //this.settings.provider_endpoint = $('#at_server').val();
|
| 854 | 854 | this.settings.language = $('#language_options').val();
|
| 855 | 855 | //this.settings.voiceMap = $('#voicemap').val();
|
| 856 | 856 | this.settings.at_generation_method = $('#at_generation_method').val();
|
| 857 | 857 | this.settings.narrator_enabled = $('#at_narrator_enabled').val();
|
| 858 | 858 | this.settings.at_narrator_text_not_inside = $('#at_narrator_text_not_inside').val();
|
| 859 | 859 | this.settings.rvc_character_voice = $('#rvc_character_voice').val();
|
| 860 | 860 | this.settings.rvc_narrator_voice = $('#rvc_narrator_voice').val();
|
| 861 | 861 | this.settings.rvc_character_pitch = $('#rvc_character_pitch').val();
|
| 862 | 862 | this.settings.rvc_narrator_pitch = $('#rvc_narrator_pitch').val();
|
| 863 | 863 | this.settings.narrator_voice_gen = $('#narrator_voice').val();
|
| 864 | 864 | // Save the updated settings
|
| 865 | 865 | saveTtsProviderSettings();
|
| 866 | 866 | }
|
| 867 | | -
|
| 867 | + |
| 868 | 868 | //#########################//
|
| 869 | 869 | // ST Handle Reload button //
|
| 870 | 870 | //#########################//
|
| 871 | | -
|
| 871 | + |
| 872 | 872 | async onRefreshClick() {
|
| 873 | 873 | try {
|
| 874 | 874 | updateStatus('Processing'); // Set status to Processing while refreshing
|
| 875 | 875 | await this.checkReady(); // Check if the TTS provider is ready
|
| 876 | 876 | await this.loadSettings(this.settings); // Reload the settings
|
| 877 | 877 | await this.checkReady(); // Check if the TTS provider is ready
|
| 878 | 878 | updateStatus(this.ready ? 'Ready' : 'Offline'); // Update the status based on readiness
|
| 879 | 879 | } catch (error) {
|
| 880 | 880 | console.error('Error during refresh:', error);
|
| 881 | 881 | updateStatus('Error'); // Set status to Error in case of failure
|
| 882 | 882 | }
|
| 883 | 883 | }
|
| 884 | | -
|
| 884 | + |
| 885 | 885 | //##################//
|
| 886 | 886 | // Preview AT Voice //
|
| 887 | 887 | //##################//
|
| 888 | | -
|
| 888 | + |
| 889 | 889 | async previewTtsVoice(voiceName) {
|
| 890 | 890 | try {
|
| 891 | 891 | // Prepare data for POST request
|
| 892 | 892 | const postData = new URLSearchParams();
|
| 893 | 893 | postData.append('voice', `${voiceName}`);
|
| 894 | | -
|
| 894 | + |
| 895 | 895 | // Add RVC parameters for V2 if applicable
|
| 896 | 896 | if (this.settings.server_version === 'v2' && this.settings.rvc_character_voice !== 'Disabled') {
|
| 897 | 897 | postData.append('rvccharacter_voice_gen', this.settings.rvc_character_voice);
|
| 898 | 898 | postData.append('rvccharacter_pitch', this.settings.rvc_character_pitch || '0');
|
| 899 | 899 | }
|
| 900 | | -
|
| 900 | + |
| 901 | 901 | // Making the POST request
|
| 902 | 902 | const response = await fetch(`${this.settings.provider_endpoint}/api/previewvoice/`, {
|
| 903 | 903 | method: 'POST',
|
| 904 | 904 | headers: {
|
| 905 | 905 | 'Content-Type': 'application/x-www-form-urlencoded',
|
| 906 | 906 | },
|
| 907 | 907 | body: postData,
|
| 908 | 908 | });
|
| 909 | | -
|
| 909 | + |
| 910 | 910 | if (!response.ok) {
|
| 911 | 911 | const errorText = await response.text();
|
| 912 | 912 | console.error('previewTtsVoice Error Response Text:', errorText);
|
| 913 | 913 | throw new Error(`HTTP ${response.status}: ${errorText}`);
|
| 914 | 914 | }
|
| 915 | | -
|
| 915 | + |
| 916 | 916 | const data = await response.json();
|
| 917 | 917 | if (data.output_file_url) {
|
| 918 | 918 | // Handle V1/V2 URL differences
|
| 919 | 919 | const fullUrl = this.settings.server_version === 'v1'
|
| 920 | 920 | ? data.output_file_url
|
| 921 | 921 | : `${this.settings.provider_endpoint}${data.output_file_url}`;
|
| 922 | | -
|
| 922 | + |
| 923 | 923 | const audioElement = new Audio(fullUrl);
|
| 924 | 924 | audioElement.play().catch(e => console.error('Error playing audio:', e));
|
| 925 | 925 | } else {
|
| 926 | 926 | console.warn('previewTtsVoice No output file URL received in the response');
|
| 927 | 927 | throw new Error('No output file URL received in the response');
|
| 928 | 928 | }
|
| 929 | 929 | } catch (error) {
|
| 930 | 930 | console.error('previewTtsVoice Exception caught during preview generation:', error);
|
| 931 | 931 | throw error;
|
| 932 | 932 | }
|
| 933 | 933 | }
|
| 934 | | -
|
| 934 | + |
| 935 | 935 | //#####################//
|
| 936 | 936 | // Populate ST voices //
|
| 937 | 937 | //#####################//
|
| 938 | | -
|
| 938 | + |
| 939 | 939 | async getVoice(voiceName, generatePreview = false) {
|
| 940 | 940 | // Ensure this.voices is populated
|
| 941 | 941 | if (this.voices.length === 0) {
|
| 942 | 942 | // Fetch voice objects logic
|
| 943 | 943 | }
|
| 944 | 944 | // Find the object where the name matches voiceName
|
| 945 | 945 | const match = this.voices.find(voice => voice.name === voiceName);
|
| 946 | 946 | if (!match) {
|
| 947 | 947 | // Error handling
|
| 948 | 948 | }
|
| 949 | 949 | // Generate preview URL only if requested
|
| 950 | 950 | if (!match.preview_url && generatePreview) {
|
| 951 | 951 | // Generate preview logic
|
| 952 | 952 | }
|
| 953 | 953 | return match; // Return the found voice object
|
| 954 | 954 | }
|
| 955 | | -
|
| 955 | + |
| 956 | 956 | //##########################################//
|
| 957 | 957 | // Generate TTS Streaming or call Standard //
|
| 958 | 958 | //##########################################//
|
| 959 | | -
|
| 959 | + |
| 960 | 960 | async generateTts(inputText, voiceId) {
|
| 961 | 961 | try {
|
| 962 | 962 | if (this.settings.at_generation_method === 'streaming_enabled') {
|
| 963 | 963 | // Construct the streaming URL
|
| 964 | 964 | const streamingUrl = `${this.settings.provider_endpoint}/api/tts-generate-streaming?text=${encodeURIComponent(inputText)}&voice=${encodeURIComponent(voiceId)}&language=${encodeURIComponent(this.settings.language)}&output_file=stream_output.wav`;
|
| 965 | 965 | console.log('Streaming URL:', streamingUrl);
|
| 966 | | -
|
| 966 | + |
| 967 | 967 | // Return the streaming URL directly
|
| 968 | 968 | return streamingUrl;
|
| 969 | 969 | } else {
|
| 970 | 970 | // For standard method
|
| 971 | 971 | const outputUrl = await this.fetchTtsGeneration(inputText, voiceId);
|
| 972 | 972 | const audioResponse = await fetch(outputUrl);
|
| 973 | 973 | if (!audioResponse.ok) {
|
| 974 | 974 | throw new Error(`HTTP ${audioResponse.status}: Failed to fetch audio data`);
|
| 975 | 975 | }
|
| 976 | 976 | return audioResponse; // Return the fetch response directly
|
| 977 | 977 | }
|
| 978 | 978 | } catch (error) {
|
| 979 | 979 | console.error('Error in generateTts:', error);
|
| 980 | 980 | throw error;
|
| 981 | 981 | }
|
| 982 | 982 | }
|
| 983 | | -
|
| 983 | + |
| 984 | | -
|
| 984 | + |
| 985 | 985 | //####################//
|
| 986 | 986 | // Generate Standard //
|
| 987 | 987 | //####################//
|
| 988 | | -
|
| 988 | + |
| 989 | 989 | async fetchTtsGeneration(inputText, voiceId) {
|
| 990 | 990 | const requestBody = new URLSearchParams({
|
| 991 | 991 | 'text_input': inputText,
|
| 992 | 992 | 'text_filtering': 'standard',
|
| 993 | 993 | 'character_voice_gen': voiceId,
|
| 994 | 994 | 'narrator_enabled': this.settings.narrator_enabled,
|
| 995 | 995 | 'narrator_voice_gen': this.settings.narrator_voice_gen,
|
| 996 | 996 | 'text_not_inside': this.settings.at_narrator_text_not_inside,
|
| 997 | 997 | 'language': this.settings.language,
|
| 998 | 998 | 'output_file_name': 'st_output',
|
| 999 | 999 | 'output_file_timestamp': 'true',
|
| 1000 | 1000 | 'autoplay': 'false',
|
| 1001 | 1001 | 'autoplay_volume': '0.8',
|
| 1002 | 1002 | });
|
| 1003 | | -
|
| 1003 | + |
| 1004 | 1004 | // Add RVC parameters only for V2
|
| 1005 | 1005 | if (this.settings.server_version === 'v2') {
|
| 1006 | 1006 | if (this.settings.rvc_character_voice !== 'Disabled') {
|
| 1007 | 1007 | requestBody.append('rvccharacter_voice_gen', this.settings.rvc_character_voice);
|
| 1008 | 1008 | requestBody.append('rvccharacter_pitch', this.settings.rvc_character_pitch || '0');
|
| 1009 | 1009 | }
|
| 1010 | 1010 | if (this.settings.rvc_narrator_voice !== 'Disabled') {
|
| 1011 | 1011 | requestBody.append('rvcnarrator_voice_gen', this.settings.rvc_narrator_voice);
|
| 1012 | 1012 | requestBody.append('rvcnarrator_pitch', this.settings.rvc_narrator_pitch || '0');
|
| 1013 | 1013 | }
|
| 1014 | 1014 | }
|
| 1015 | | -
|
| 1015 | + |
| 1016 | 1016 | try {
|
| 1017 | 1017 | const response = await doExtrasFetch(
|
| 1018 | 1018 | `${this.settings.provider_endpoint}/api/tts-generate`,
|
| 1019 | 1019 | {
|
| 1020 | 1020 | method: 'POST',
|
| 1021 | 1021 | headers: {
|
| 1022 | 1022 | 'Content-Type': 'application/x-www-form-urlencoded',
|
| 1023 | 1023 | 'Cache-Control': 'no-cache',
|
| 1024 | 1024 | },
|
| 1025 | 1025 | body: requestBody,
|
| 1026 | 1026 | },
|
| 1027 | 1027 | );
|
| 1028 | | -
|
| 1028 | + |
| 1029 | 1029 | if (!response.ok) {
|
| 1030 | 1030 | const errorText = await response.text();
|
| 1031 | 1031 | console.error('fetchTtsGeneration Error Response Text:', errorText);
|
| 1032 | 1032 | throw new Error(`HTTP ${response.status}: ${errorText}`);
|
| 1033 | 1033 | }
|
| 1034 | 1034 | const data = await response.json();
|
| 1035 | | -
|
| 1035 | + |
| 1036 | 1036 | // Handle V1/V2 URL differences
|
| 1037 | 1037 | const outputUrl = this.settings.server_version === 'v1'
|
| 1038 | 1038 | ? data.output_file_url // V1 returns full URL
|
| 1039 | 1039 | : `${this.settings.provider_endpoint}${data.output_file_url}`; // V2 returns relative path
|
| 1040 | | -
|
| 1040 | + |
| 1041 | 1041 | return outputUrl;
|
| 1042 | 1042 | } catch (error) {
|
| 1043 | 1043 | console.error('[fetchTtsGeneration] Exception caught:', error);
|
| 1044 | 1044 | throw error;
|
| 1045 | 1045 | }
|
| 1046 | 1046 | }
|
| 1047 | 1047 | }
|
| 1048 | | -
|
| 1048 | + |
| 1049 | 1049 | //#########################//
|
| 1050 | 1050 | // Update Status Messages //
|
| 1051 | 1051 | //#########################//
|
| 1052 | | -
|
| 1052 | + |
| 1053 | 1053 | function updateStatus(message) {
|
| 1054 | 1054 | const statusElement = document.getElementById('status_info');
|
| 1055 | 1055 | if (statusElement) {
|
| 1056 | 1056 | statusElement.textContent = message;
|
| 1057 | 1057 | switch (message) {
|
| 1058 | 1058 | case 'Offline':
|
| 1059 | 1059 | statusElement.style.color = 'red';
|
| 1060 | 1060 | break;
|
| 1061 | 1061 | case 'Ready':
|
| 1062 | 1062 | statusElement.style.color = 'lightgreen';
|
| 1063 | 1063 | break;
|
| 1064 | 1064 | case 'Processing':
|
| 1065 | 1065 | statusElement.style.color = 'blue';
|
| 1066 | 1066 | break;
|
| 1067 | 1067 | case 'Error':
|
| 1068 | 1068 | statusElement.style.color = 'red';
|
| 1069 | 1069 | break;
|
| 1070 | 1070 | }
|
| 1071 | 1071 | }
|
| 1072 | 1072 | }
|